package com.hw.one.dam2.service;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;

import com.hw.one.dam2.dao.*;
import com.hw.one.dam2.param.RegionSiteParam;
import com.hw.one.dam2.param.SiteAirParam;
import com.hw.one.dam2.po.*;
import com.hw.one.dam2.util.MathCalculateUtil;
import com.hw.one.dam2.util.UserSiteUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hw.one.dam2.common.DamConstant;
import com.hw.one.dam2.common.DataTypeEnum;
import com.hw.one.dam2.common.ScopeTypeEnum;
import com.hw.one.dam2.common.SiteTypeEnum;
import com.hw.one.dam2.common.SortScopeTypeEnum;
import com.hw.one.dam2.entity.IAQIEntity;
import com.hw.one.dam2.entity.PollutionIndustryEntity;
import com.hw.one.dam2.entity.WaterSurfaceEntity;
import com.hw.one.dam2.param.CityAirParam;
import com.hw.one.dam2.util.AQIProcess;
import com.hw.one.dam2.util.WeatherUtil;
import com.hw.one.ext.util.UserUtil;
import com.hw.one.util.DateTimeUtil;
import org.springframework.util.StringUtils;

@Service(value = "cityAirService")
public class CityAirService implements ICityAirService {

    @Autowired
    private IRegionSiteDao regionSiteDao;

    @Autowired
    private ISiteAirDao siteAirDao;

    @Autowired
    private IGPointAirService gPoinAirService;

    @Autowired
    private ISmallAirService smallAirService;

    @Autowired
    private IIndustryPollutionService industryPollutionService;

    @Autowired
    private IWaterPollutionService waterPollutionService;

    @Autowired
    private IWaterSurfaceService waterSurfaceService;

    @Autowired
    private ILampBlackService lampBlackService;

    @Autowired
    private ILampBlackDao lampBlackDao;

    @Autowired
    private IRegionAirDao regionAirDao;

    @Autowired
    private IWeatherDao weatherDao;
    // 污染源
    @Autowired
    private IPollutionService pollutionService;

    private DecimalFormat df = new DecimalFormat("#0.00");

    @SuppressWarnings({"rawtypes", "unchecked"})
    @Override
    public List<IAQIEntity> findCityIAQIByRegionCodeAndTime(Map<String, Object> paraMap) throws Exception {
        // 排名范围类型: 全国排名 nationalSort;省内排名 provinceSort;区县排名 areaCountySort;办事处排名
        // 新增： seventyFourCitySort;74城市排名; twentySixCitySort;2+26城市排名;
        // officeSort
        String sortScopeType = paraMap.get("sortScopeType").toString();

        // 数据类型 时报hourData；日报dayData；月报monthData；年报yearData
        String dataType = paraMap.get("dataType").toString();

        // 区域范围类型：全部allScope；市区 cityScope；郊县 outskirtsScope
        String scopeType = paraMap.get("scopeType").toString();
        // 开始时间
        String startTime = paraMap.get("startTime").toString();
        // 结束时间
        String endTime = paraMap.get("endTime").toString();

        // 根据登录用户，查询用户所属行政区域
        Map<String, Object> region = UserUtil.getRegion();
        String userRegionCode = (String) region.get("regionCode");
        // 市级名称
        String cityCode = null;
        String provanceCode = null;
        /**
         * 根据当前登录用户区域，查询该区域的上级区域
         */
        List<Map<String, Object>> parentRegionList = regionSiteDao.findParentRegionInfoByRegionCode(userRegionCode);
        // 把登录用户所属省份、和市编码，读取出来
        for (Map<String, Object> parentRegionMap : parentRegionList) {
            String retionType = String.valueOf(parentRegionMap.get("regionType"));
            if ("10".equals(retionType)) {
                provanceCode = String.valueOf(parentRegionMap.get("regionCode"));
            }
            if ("20".equals(retionType)) {
                cityCode = String.valueOf(parentRegionMap.get("regionCode"));
            }
        }

        if (null == provanceCode) {
            provanceCode = userRegionCode;
        }
        if (null == cityCode) {
            cityCode = userRegionCode;
        }

        // 查询区域的条件Map
        Map<String, String> regoinTypeMap = new HashMap<String, String>();
        //封装参数
        if (SortScopeTypeEnum.NATIONAL_SORT.getValue().equals(sortScopeType)) {
            // 省内排名
        } else if (SortScopeTypeEnum.PROVINCE_SORT.getValue().equals(sortScopeType)) {
            regoinTypeMap.put("regionCode", provanceCode);
            // 区县排名
        } else if (SortScopeTypeEnum.AREA_COUNTY_SORT.getValue().equals(sortScopeType)) {
            regoinTypeMap.put("regionCode", cityCode);
        } else if (SortScopeTypeEnum.OFFICE_SORT.getValue().equals(sortScopeType)) {
            regoinTypeMap.put("regionCode", userRegionCode);
        } else if (SortScopeTypeEnum.SEVENTY_FOUR_CITY_SORT.getValue().equals(sortScopeType)) {
            regoinTypeMap.put("rankingType", "74city");
        } else if (SortScopeTypeEnum.TWENTY_SIX_CITY_SORT.getValue().equals(sortScopeType)) {
            regoinTypeMap.put("rankingType", "2_26city");
        } else {
            return new ArrayList<IAQIEntity>();
        }

        regoinTypeMap.put("sortScorpeType", sortScopeType);

        // 按照区域编码，查询出区域信息
        List<Map<String, Object>> regionInfoList = null;
        if (SortScopeTypeEnum.NATIONAL_SORT.getValue().equals(sortScopeType)
            || SortScopeTypeEnum.PROVINCE_SORT.getValue().equals(sortScopeType)
            || SortScopeTypeEnum.AREA_COUNTY_SORT.getValue().equals(sortScopeType)
            || SortScopeTypeEnum.OFFICE_SORT.getValue().equals(sortScopeType)) {
            regionInfoList = regionSiteDao.findRegionListByRegionType(regoinTypeMap);
        } else if (SortScopeTypeEnum.SEVENTY_FOUR_CITY_SORT.getValue().equals(sortScopeType)
            || SortScopeTypeEnum.TWENTY_SIX_CITY_SORT.getValue().equals(sortScopeType)) {
            regionInfoList = regionSiteDao.findRegionListByRankingType(regoinTypeMap);
        } else {
        }

        if (null == regionInfoList) {
            return new ArrayList<IAQIEntity>();
        }

        // 区域列表
        List<String> regionCodeList = new ArrayList<String>();
        // 区域类型 是市区
        if (ScopeTypeEnum.CITY_SCOPE.getValue().equals(scopeType)) {
            for (Map<String, Object> regionMap : regionInfoList) {
                String regionType = regionMap.get("regionType").toString();
                if ("22".equals(regionType)) {
                    regionCodeList.add(regionMap.get("regionCode").toString());
                }
            }
            // 区域类型 是郊县
        } else if (ScopeTypeEnum.OUTSKIRTS_SCOPE.getValue().equals(scopeType)) {
            for (Map<String, Object> regionMap : regionInfoList) {
                String regionType = regionMap.get("regionType").toString();
                if ("24".equals(regionType)) {
                    regionCodeList.add(regionMap.get("regionCode").toString());
                }
            }
            // 查询全部区域
        } else {
            for (Map<String, Object> regionMap : regionInfoList) {
                regionCodeList.add(regionMap.get("regionCode").toString());
            }
        }

        if (regionCodeList.size() == 0) {
            return new ArrayList<IAQIEntity>();
        }

        // 拼凑查询条件
        CityAirParam paramPO = new CityAirParam();

        // 区域列表 查询条件
        paramPO.setRegionCodes(regionCodeList);
        paramPO.setStartTime(startTime);
        paramPO.setEndTime(endTime);

        List<IAQIEntity> iaqiList = new ArrayList<IAQIEntity>();

        // 小时数据
        if (DataTypeEnum.HOUR_DATA.getValue().equals(dataType)) {

            List<RegionAirQualityPO> hourCIList = regionAirDao.findRegionHourDataByRegionCodesAndTime(paramPO);

            int index = 1;
//			// 填充 区域 名称
//			for (RegionAirQualityPO regionAirQualityPO : hourCIList) {
//				Map<String, Object> hourCIMap = new HashMap<>();
//				hourCIMap.put("index", index++);
//				String regionCode = regionAirQualityPO.getREGIONCODE();
//				// 从数据库中读取的时间
//				String oragMonitorTime = regionAirQualityPO.getMONITORTIME();
//				if (null != oragMonitorTime) {
//					// 把时间格式化
//					hourCIMap.put("MONITORTIME", oragMonitorTime.substring(0, 16));
//				}
//
//				for (Map<String, Object> regionMap : regionInfoList) {
//					String regionCodeInfo = (String) regionMap.get("regionCode");
//					if (regionCode.equals(regionCodeInfo)) {
//						hourCIMap.put("regionName", regionMap.get("regionName"));
//						break;
//					}
//				}
//			}

            IAQIEntity iaqiEntity = null;
            for (RegionAirQualityPO hourMap : hourCIList) {
                iaqiEntity = new IAQIEntity();
                iaqiEntity.setIndex(index);
                index++;
                iaqiEntity.setRegionName(hourMap.getREGIONNAME());
                iaqiEntity.setCompositeValue(hourMap.getCOMPOSITEVALUE());
                iaqiEntity.setAqi(hourMap.getAQI());
                iaqiEntity.setPm10(hourMap.getPM10().getCONCENTRATION());
                iaqiEntity.setPm10IAQI(hourMap.getPM10().getSUBINDEX());
                iaqiEntity.setPm25(hourMap.getPM25().getCONCENTRATION());
                iaqiEntity.setPm25IAQI(hourMap.getPM25().getSUBINDEX());
                iaqiEntity.setSo2(hourMap.getSO2().getCONCENTRATION());
                iaqiEntity.setSo2IAQI(hourMap.getSO2().getSUBINDEX());
                iaqiEntity.setNo2(hourMap.getNO2().getCONCENTRATION());
                iaqiEntity.setNo2IAQI(hourMap.getNO2().getSUBINDEX());
                iaqiEntity.setCo(hourMap.getCO().getCONCENTRATION());
                iaqiEntity.setCoIAQI(hourMap.getCO().getSUBINDEX());
                iaqiEntity.setO3(hourMap.getO3().getCONCENTRATION());
                iaqiEntity.setO3IAQI(hourMap.getO3().getSUBINDEX());

                iaqiList.add(iaqiEntity);
            }

            // 日数据
        } else if (DataTypeEnum.DAY_DATA.getValue().equals(dataType)) {
            // 获取数据中的最新数据
            // 查询 日 综合指数
            List<RegionAirQualityPO> dayCIList = regionAirDao.findRegionDayDataByRegionCodesAndTime(paramPO);

            int index = 1;
            // 填充 区域 名称
//			for (Map dayCIMap : dayCIList) {
//				dayCIMap.put("index", index++);
//				String regionCode = dayCIMap.get("REGIONCODE").toString();
//				// 从数据库中读取的时间
//				String oragMonitorTime = dayCIMap.get("MONITORTIME").toString();
//				if (null != oragMonitorTime) {
//					dayCIMap.put("MONITORTIME", oragMonitorTime.substring(0, 10));
//				}
//				for (Map<String, Object> regionMap : regionInfoList) {
//					String regionCodeInfo = (String) regionMap.get("regionCode");
//					if (regionCode.equals(regionCodeInfo)) {
//						dayCIMap.put("regionName", regionMap.get("regionName"));
//						continue;
//					}
//				}
//			}

            IAQIEntity iaqiEntity = null;
            for (RegionAirQualityPO dayMap : dayCIList) {
                iaqiEntity = new IAQIEntity();
                iaqiEntity.setIndex(index);
                index++;
                iaqiEntity.setRegionName(dayMap.getREGIONNAME());
                iaqiEntity.setCompositeValue(dayMap.getCOMPOSITEVALUE());
                iaqiEntity.setAqi(dayMap.getAQI());
                iaqiEntity.setPm10(dayMap.getPM10().getCONCENTRATION());
                iaqiEntity.setPm10IAQI(dayMap.getPM10().getSUBINDEX());
                iaqiEntity.setPm25(dayMap.getPM25().getCONCENTRATION());
                iaqiEntity.setPm25IAQI(dayMap.getPM25().getSUBINDEX());
                iaqiEntity.setSo2(dayMap.getSO2().getCONCENTRATION());
                iaqiEntity.setSo2IAQI(dayMap.getSO2().getSUBINDEX());
                iaqiEntity.setNo2(dayMap.getNO2().getCONCENTRATION());
                iaqiEntity.setNo2IAQI(dayMap.getNO2().getSUBINDEX());
                iaqiEntity.setCo(dayMap.getCO().getCONCENTRATION());
                iaqiEntity.setCoIAQI(dayMap.getCO().getSUBINDEX());
                iaqiEntity.setO3(dayMap.getO3().getCONCENTRATION());
                iaqiEntity.setO3IAQI(dayMap.getO3().getSUBINDEX());
                iaqiList.add(iaqiEntity);
            }
            // 月累计数据
        } else if (DataTypeEnum.MONTH_DATA.getValue().equals(dataType)) {
            List<RegionAirQualityPO> monthCIList = regionAirDao.findRegionMonthDataByRegionCodesAndTime(paramPO);

            int index = 1;
            // 填充 区域 名称
//			for (Map totalCIMap : monthCIList) {
//				totalCIMap.put("index", index++);
//				String regionCode = totalCIMap.get("REGIONCODE").toString();
//				// 从数据库中读取的时间
//				String oragMonitorTime = totalCIMap.get("MONITORTIME").toString();
//				if (null != oragMonitorTime) {
//					totalCIMap.put("MONITORTIME", oragMonitorTime.substring(0, 10));
//				}
//				for (Map<String, Object> regionMap : regionInfoList) {
//					String regionCodeInfo = (String) regionMap.get("regionCode");
//					if (regionCode.equals(regionCodeInfo)) {
//						totalCIMap.put("regionName", regionMap.get("regionName"));
//						continue;
//					}
//				}
//			}

            IAQIEntity iaqiEntity = null;
            for (RegionAirQualityPO dayMap : monthCIList) {
                iaqiEntity = new IAQIEntity();
                iaqiEntity.setIndex(index);
                index++;
                iaqiEntity.setRegionName(dayMap.getREGIONNAME());
                iaqiEntity.setCompositeValue(dayMap.getCOMPOSITEVALUE());
                iaqiEntity.setAqi(dayMap.getAQI());
                iaqiEntity.setPm10(dayMap.getPM10().getCONCENTRATION());
                iaqiEntity.setPm10IAQI(dayMap.getPM10().getSUBINDEX());
                iaqiEntity.setPm25(dayMap.getPM25().getCONCENTRATION());
                iaqiEntity.setPm25IAQI(dayMap.getPM25().getSUBINDEX());
                iaqiEntity.setSo2(dayMap.getSO2().getCONCENTRATION());
                iaqiEntity.setSo2IAQI(dayMap.getSO2().getSUBINDEX());
                iaqiEntity.setNo2(dayMap.getNO2().getCONCENTRATION());
                iaqiEntity.setNo2IAQI(dayMap.getNO2().getSUBINDEX());
                iaqiEntity.setCo(dayMap.getCO().getCONCENTRATION());
                iaqiEntity.setCoIAQI(dayMap.getCO().getSUBINDEX());
                iaqiEntity.setO3(dayMap.getO3().getCONCENTRATION());
                iaqiEntity.setO3IAQI(dayMap.getO3().getSUBINDEX());
                iaqiList.add(iaqiEntity);
            }
            // 年累计数据
        } else if (DataTypeEnum.YEAR_DATA.getValue().equals(dataType)) {
            List<RegionAirQualityPO> yearCIList = regionAirDao.findRegionYearDataByRegionCodesAndTime(paramPO);

            int index = 1;
//			// 填充 区域 名称
//			for (Map totalCIMap : yearCIList) {
//				totalCIMap.put("index", index++);
//				String regionCode = totalCIMap.get("REGIONCODE").toString();
//				// 从数据库中读取的时间
//				String oragMonitorTime = totalCIMap.get("MONITORTIME").toString();
//				if (null != oragMonitorTime) {
//					totalCIMap.put("MONITORTIME", oragMonitorTime.substring(0, 10));
//				}
//				for (Map<String, Object> regionMap : regionInfoList) {
//					String regionCodeInfo = (String) regionMap.get("regionCode");
//					if (regionCode.equals(regionCodeInfo)) {
//						totalCIMap.put("regionName", regionMap.get("regionName"));
//						continue;
//					}
//				}
//			}

            IAQIEntity iaqiEntity = null;
            for (RegionAirQualityPO dayMap : yearCIList) {
                iaqiEntity = new IAQIEntity();
                iaqiEntity.setIndex(index);
                index++;
                iaqiEntity.setRegionName(dayMap.getREGIONNAME());
                iaqiEntity.setCompositeValue(dayMap.getCOMPOSITEVALUE());
                iaqiEntity.setAqi(dayMap.getAQI());
                iaqiEntity.setPm10(dayMap.getPM10().getCONCENTRATION());
                iaqiEntity.setPm10IAQI(dayMap.getPM10().getSUBINDEX());
                iaqiEntity.setPm25(dayMap.getPM25().getCONCENTRATION());
                iaqiEntity.setPm25IAQI(dayMap.getPM25().getSUBINDEX());
                iaqiEntity.setSo2(dayMap.getSO2().getCONCENTRATION());
                iaqiEntity.setSo2IAQI(dayMap.getSO2().getSUBINDEX());
                iaqiEntity.setNo2(dayMap.getNO2().getCONCENTRATION());
                iaqiEntity.setNo2IAQI(dayMap.getNO2().getSUBINDEX());
                iaqiEntity.setCo(dayMap.getCO().getCONCENTRATION());
                iaqiEntity.setCoIAQI(dayMap.getCO().getSUBINDEX());
                iaqiEntity.setO3(dayMap.getO3().getCONCENTRATION());
                iaqiEntity.setO3IAQI(dayMap.getO3().getSUBINDEX());
                iaqiList.add(iaqiEntity);
            }

        }
        // 如果是74城市或者2+26城市，需要显示所有的城市
        if (SortScopeTypeEnum.SEVENTY_FOUR_CITY_SORT.getValue().equals(sortScopeType)
            || SortScopeTypeEnum.TWENTY_SIX_CITY_SORT.getValue().equals(sortScopeType)) {
            Boolean isContainRegion = false;
            List<IAQIEntity> emptyList = new ArrayList<>();
            int index = iaqiList.size() + 1;
            for (Map<String, Object> regionMap : regionInfoList) {
                String regionName = regionMap.get("regionName").toString();
                IAQIEntity iaqiEntity = null;
                for (IAQIEntity entity : iaqiList) {
                    if (entity.getRegionName().equals(regionName)) {
                        isContainRegion = true;
                        break;
                    }
                }
                if (!isContainRegion) {
                    iaqiEntity = new IAQIEntity();
                    iaqiEntity.setIndex(index++);
                    iaqiEntity.setRegionName(regionName);
                    iaqiEntity.setCompositeValue("-");
                    iaqiEntity.setAqi("-");
                    iaqiEntity.setPm10("-");
                    iaqiEntity.setPm10IAQI("-");
                    iaqiEntity.setPm25("-");
                    iaqiEntity.setPm25IAQI("-");
                    iaqiEntity.setSo2("-");
                    iaqiEntity.setSo2IAQI("-");
                    iaqiEntity.setNo2("-");
                    iaqiEntity.setNo2IAQI("-");
                    iaqiEntity.setCo("-");
                    iaqiEntity.setCoIAQI("-");
                    iaqiEntity.setO3("-");
                    iaqiEntity.setO3IAQI("-");
                    emptyList.add(iaqiEntity);
                }
            }
            iaqiList.addAll(emptyList);
        }

        return iaqiList;
    }

    @SuppressWarnings({"unchecked", "rawtypes"})
    @Override
    public Map<String, Object> findSiteAndDetailInfoBySiteType(Map<String, Object> paraMap) throws Exception {
        /**
         * 国控点 nationalSite 省控点 provinceSite 小型站 smallAirSite 工业源 industrySite
         * 扬尘 raiseDustSite 油烟 lampblackSite 喷漆房 sprayBoothSite 加油站
         * gasStationSite 工业废水 waterPollutionSite 水质断面 waterSurfaceSite 所有标准站
         * allNationalSite 所有空气站 allAirSite 所有污染源 allPollutionSite 所有站点 allSite
         */
        String pointType = paraMap.get("pointType").toString();

        // 判断用户是否有访问权限
        /* 判断开始 */
        if (SiteTypeEnum.ALL_NATIONAL_SITE.getValue().equals(pointType) || SiteTypeEnum.NATIONAL_SITE.getValue().equals(pointType) ||
            SiteTypeEnum.PROVINCE_SITE.getValue().equals(pointType) || SiteTypeEnum.CITY_SITE.getValue().equals(pointType)) {
            Boolean containNationalSite = UserSiteUtil.userIsNotContainSiteTypes("001");
            Boolean containProvinceSite = UserSiteUtil.userIsNotContainSiteTypes("002");
            Boolean containCitySite = UserSiteUtil.userIsNotContainSiteTypes("003");
            if (SiteTypeEnum.ALL_NATIONAL_SITE.getValue().equals(pointType)) {
                if (containNationalSite && !containProvinceSite) {
                    pointType = SiteTypeEnum.NATIONAL_SITE.getValue();
                } else if (!containNationalSite && containProvinceSite) {
                    pointType = SiteTypeEnum.PROVINCE_SITE.getValue();
                } else if (!containNationalSite && containCitySite) {
                    pointType = SiteTypeEnum.CITY_SITE.getValue();
                } else if (!containNationalSite && !containProvinceSite) {
                    return new HashMap<>();
                }
            } else if (SiteTypeEnum.NATIONAL_SITE.getValue().equals(pointType) && containNationalSite) {
                pointType = SiteTypeEnum.NATIONAL_SITE.getValue();
            } else if (SiteTypeEnum.PROVINCE_SITE.getValue().equals(pointType) && containProvinceSite) {
                pointType = SiteTypeEnum.PROVINCE_SITE.getValue();
            } else if (SiteTypeEnum.CITY_SITE.getValue().equals(pointType) && containCitySite) {
                pointType = SiteTypeEnum.CITY_SITE.getValue();
            } else {
                return new HashMap<>();
            }
        } else if (SiteTypeEnum.SMALL_AIR_SITE.getValue().equals(pointType) && UserSiteUtil.userIsNotContainSiteTypes("004")) {
        } else if (SiteTypeEnum.INDUSTRY_SITE.getValue().equals(pointType) && UserSiteUtil.userIsNotContainSiteTypes("101")) {
        } else if (SiteTypeEnum.RAISE_DUST_SITE.getValue().equals(pointType) && UserSiteUtil.userIsNotContainSiteTypes("102")) {
        } else if (SiteTypeEnum.WATER_POLLUTION_SITE.getValue().equals(pointType) && UserSiteUtil.userIsNotContainSiteTypes("201")) {
        } else if (SiteTypeEnum.WATER_SURFACE_SITE.getValue().equals(pointType) && UserSiteUtil.userIsNotContainSiteTypes
            ("006,007,008,009,010,011")) {
        } else if (SiteTypeEnum.LAMPBLACK_SITE.getValue().equals(pointType) && UserSiteUtil.userIsNotContainSiteTypes("103")) {
        } else if (SiteTypeEnum.SPRAY_BOOTH_SITE.getValue().equals(pointType) && UserSiteUtil.userIsNotContainSiteTypes("104")) {
        } else if (SiteTypeEnum.GAS_STATION_SITE.getValue().equals(pointType) && UserSiteUtil.userIsNotContainSiteTypes("105")) {
        } else {
            return new HashMap<>();
        }
        /* 判断结束 */

        Map<String, Object> region = UserUtil.getRegion();
        String userRegionCode = (String) region.get("regionCode");   //当前用户所在的区域
        String userRegionName = (String) region.get("regionName");

        /**
         * 根据当前登录用户区域，查询该区域的上级区域
         */
        List<Map<String, Object>> parentRegionList = regionSiteDao.findParentRegionInfoByRegionCode(userRegionCode);

        // 地图的中心点位
        JSONObject centerPointObj = new JSONObject();
        for (Map<String, Object> parentRegionMap : parentRegionList) {
            String regionCode = String.valueOf(parentRegionMap.get("regionCode"));
            if (userRegionCode.equals(regionCode)) {
                centerPointObj.put("lng", parentRegionMap.get("longitude"));
                centerPointObj.put("lat", parentRegionMap.get("latitude"));
            }
        }

        String cityCode = null;
        // 把登录用户所属省份、和市编码，读取出来
        for (Map<String, Object> parentRegionMap : parentRegionList) {
            String retionType = String.valueOf(parentRegionMap.get("regionType"));
            // 市级名称
            if ("20".equals(retionType)) {
                cityCode = String.valueOf(parentRegionMap.get("regionCode"));
                break;
            }
        }

        // 查询实时天气，填充国控站，小型站温度、湿度、风向、风速数据
        Map cityLiveWeatherMap = (Map) weatherDao.findCityLiveWeatherByRegionCode(cityCode);

        if (SiteTypeEnum.SMALL_AIR_SITE.getValue().equals(pointType)
            || SiteTypeEnum.LAMPBLACK_SITE.getValue().equals(pointType)
            || SiteTypeEnum.SPRAY_BOOTH_SITE.getValue().equals(pointType)
            || SiteTypeEnum.RAISE_DUST_SITE.getValue().equals(pointType)
            || SiteTypeEnum.WATER_POLLUTION_SITE.getValue().equals(pointType)
            || SiteTypeEnum.WATER_SURFACE_SITE.getValue().equals(pointType)
            || SiteTypeEnum.GAS_STATION_SITE.getValue().equals(pointType)
            || SiteTypeEnum.INDUSTRY_SITE.getValue().equals(pointType)) {
            cityCode = userRegionCode;

        }

        if (null == cityCode) {
            cityCode = userRegionCode;
        }

//        Map<String, String> paraSiteMap = new HashMap<String, String>();
//        paraSiteMap.put("regionCode", cityCode);
//        paraSiteMap.put("siteType", pointType);
        RegionSiteParam siteParam = new RegionSiteParam();
        siteParam.setRegionCode(cityCode);  //当前用户的所在城市的区域编码
        siteParam.setSiteType(pointType);   //
        List<Map<String, Object>> siteInfoList = regionSiteDao.findSiteInfoByRegionCodeAndSiteType(siteParam);

        if (null == siteInfoList || siteInfoList.size() == 0) {
            return new HashMap<>();
        }

        List<String> siteCodeList = new ArrayList<String>();
        List<String> snCodeList = new ArrayList<String>();
        for (Map<String, Object> siteMap : siteInfoList) {
            siteCodeList.add(String.valueOf(siteMap.get("siteCode")));
            snCodeList.add(String.valueOf(siteMap.get("SNCode")));
        }

        List<Map<String, Object>> returnList = null;

        // 国控站 和 省控站 小型站
        if (SiteTypeEnum.NATIONAL_SITE.getValue().equals(pointType)
            || SiteTypeEnum.PROVINCE_SITE.getValue().equals(pointType)
            || SiteTypeEnum.CITY_SITE.getValue().equals(pointType)
            || SiteTypeEnum.ALL_NATIONAL_SITE.getValue().equals(pointType)
            || SiteTypeEnum.SMALL_AIR_SITE.getValue().equals(pointType)
            ) {

            // 查询 分钟数据 （30分钟）
            List<Map<String, Object>> pointNewDataList = gPoinAirService
                .findGPointNewMinuteDataBySiteCodeList(siteCodeList);

            List<Map<String, Object>> pointNewDataMapList = new ArrayList<>();
            List<Map<String, Object>> pointNewDataEmptyList = new ArrayList<>();

            List<String> pointCodeNoDataList = new ArrayList<>();
            // 先循环站点信息
            for (Map<String, Object> siteMap : siteInfoList) {
                boolean flag = false;
                String siteCode = (String) siteMap.get("siteCode");
                // 循环分钟数据
                for (Map<String, Object> hourPO : pointNewDataList) {
                    if (siteCode.equals(hourPO.get("siteCode"))) {
                        flag = true;
                        // 从数据库中读取的时间
                        String oragMonitorTime = hourPO.get("monitorTime").toString();
                        if (null != oragMonitorTime) {
                            hourPO.put("monitorTime", oragMonitorTime.substring(0, 16));
                        }
                        hourPO.put("siteName", siteMap.get("siteName"));
                        hourPO.put("siteTypeCode", siteMap.get("siteTypeCode"));
                        hourPO.put("Latitude", siteMap.get("Latitude"));
                        hourPO.put("Longitude", siteMap.get("Longitude"));
                        // 温度、湿度、风向、风速；有值则取值，无值默认为城市天气实时数据；
                        if ("".equals(hourPO.get("temp")) || "".equals(hourPO.get("hum")) || "".equals(hourPO.get("windDirection")) || "".equals(hourPO.get("windSpeed"))) {
                            setRealTimeWeather(hourPO, cityLiveWeatherMap);
                        }

                        if (!isOrNotEmptyData(hourPO) && !isOrNotInvalidAqiData(hourPO)) {
                            putSiteStatus(hourPO, "1111"); // 正常数据
                            pointNewDataMapList.add(hourPO);
                            flag = true;
                        }
                        break;
                    }
                }
                // 如果没有数据
                if (!flag) {
                    pointCodeNoDataList.add(siteCode);
                    pointNewDataEmptyList.add(siteMap);
                }
            }

            if (pointCodeNoDataList.size() > 0) {
                // 如果为空,查询最新的小时数据
                List<Map<String, Object>> gpointNewDataList = gPoinAirService.findGPointNewHourDataBySiteCodes(pointCodeNoDataList);

                List<Map<String, Object>> hourSiteEmptyDataList = new ArrayList<>();
                List<Map<String, Object>> hourSiteNoDataList = new ArrayList<>();
                for (Map siteMap : pointNewDataEmptyList) {
                    String siteCode = (String) siteMap.get("siteCode");
                    boolean flag = false;
                    // 循环小时数据
                    for (Map hourPO : gpointNewDataList) {
                        if (siteCode.equals(hourPO.get("siteCode"))) {
                            flag = true;
                            // 从数据库中读取的时间
                            String oragMonitorTime = hourPO.get("monitorTime").toString();
                            if (null != oragMonitorTime) {
                                hourPO.put("monitorTime", oragMonitorTime.substring(0, 16));
                            }
                            hourPO.put("siteName", siteMap.get("siteName"));
                            hourPO.put("siteTypeCode", siteMap.get("siteTypeCode"));
                            hourPO.put("Latitude", siteMap.get("Latitude"));
                            hourPO.put("Longitude", siteMap.get("Longitude"));
                            // 温度、湿度、风向、风速；有值则取值，无值默认为城市天气实时数据；
                            if ("".equals(hourPO.get("temp")) || "".equals(hourPO.get("hum")) || "".equals(hourPO.get("windDirection")) || "".equals(hourPO.get("windSpeed"))) {
                                setRealTimeWeather(hourPO, cityLiveWeatherMap);
                            }

                            if (!isOrNotEmptyData(hourPO) && !isOrNotInvalidAqiData(hourPO)) {
                                putSiteStatus(hourPO, "1111"); // 正常数据
                                pointNewDataMapList.add(hourPO);
                            } else {
                                dealHourPo(hourPO);
                                hourPO.put("temp", "-");
                                hourPO.put("hum", "-");
                                hourPO.put("windDirection", "-");
                                hourPO.put("windSpeed", "-");
                                putSiteStatus(hourPO, "0000"); // 数据为空
                                hourSiteEmptyDataList.add(hourPO);
                            }
                            break;
                        }
                    }
                    if (!flag) {
                        hourSiteNoDataList.add(siteMap);
                    }
                }
                pointNewDataMapList.addAll(hourSiteEmptyDataList);
                // 处理未记录数据
                for (Map<String, Object> siteMap : hourSiteNoDataList) {
                    dealHourPo(siteMap);
                    siteMap.put("temp", "-");
                    siteMap.put("hum", "-");
                    siteMap.put("windDirection", "-");
                    siteMap.put("windSpeed", "-");
                    putSiteStatus(siteMap, "0001"); // 未记录数据
                    pointNewDataMapList.add(siteMap);
                }
            }

            Collections.sort(pointNewDataMapList, (a, b) -> {
                if (null == a.get("aqi") && null == b.get("aqi")) {
                    return 0;
                }
                if (null == a.get("aqi") || "-".equals(String.valueOf(a.get("aqi")))) {
                    return 1;
                }
                if (null == b.get("aqi") || "-".equals(String.valueOf(b.get("aqi")))) {
                    return -1;
                }
                Double one = Double.valueOf(a.get("aqi").toString());
                Double two = Double.valueOf(b.get("aqi").toString());
                return (int) (two - one);
            });

            returnList = pointNewDataMapList;
            //工业源
        } else if (SiteTypeEnum.INDUSTRY_SITE.getValue().equals(pointType)) {

            // 查询工业源 排口信息
            List<Map<String, Object>> outputInfoList = regionSiteDao.findIndustyOutputNameBySiteCode(siteCodeList);
            // 排口编号列表
            List<String> outputCodeList = new ArrayList<String>();
            for (Map<String, Object> outputMap : outputInfoList) {
                outputCodeList.add(String.valueOf(outputMap.get("outputCode")));
            }

            List<Map<String, Object>> psList = industryPollutionService
                .findPollutionNewHourDataByPSCodeAndOutputCodes(siteCodeList, outputCodeList);

            List<Map<String, Object>> pollutionList = new ArrayList<Map<String, Object>>();
            List<Map<String, Object>> pollutionEmptyList = new ArrayList<Map<String, Object>>();

            List<String> pollutionCodeList = new ArrayList<>();
            for (Map<String, Object> siteMap : siteInfoList) {
                Object siteCodeObj = siteMap.get("siteCode");

                for (Map<String, Object> dataMap : psList) {
                    Object psCode = dataMap.get("PSCode");
                    if (siteCodeObj.equals(psCode)) {
                        if (pollutionCodeList.contains(siteCodeObj)) {
                            continue;
                        }
                        pollutionCodeList.add(psCode.toString());
                        Object monitorTimeObj = dataMap.get("MONITORTIME");
                        if (null != monitorTimeObj && !"".equals(monitorTimeObj)) {
                            monitorTimeObj = String.valueOf(monitorTimeObj).substring(0, 16);
                        }
                        siteMap.put("monitorTime", monitorTimeObj);
                        siteMap.put("AvgStrength001", null == dataMap.get("AvgStrength001") || "".equals(dataMap.get("AvgStrength001")) ? "-" : dataMap.get("AvgStrength001"));
                        siteMap.put("AvgStrength002", dataMap.get("AvgStrength002"));
                        siteMap.put("AvgStrength003", dataMap.get("AvgStrength003"));
                        siteMap.put("AvgZsStrength003", dataMap.get("AvgZsStrength003"));
                        siteMap.put("AvgZsStrength002", dataMap.get("AvgZsStrength002"));
                        siteMap.put("AvgZsStrength001", dataMap.get("AvgZsStrength001"));
                        if (isOrNotEmptyPollutionData(siteMap)) {
                            dealPollutionMap(siteMap);
                            putSiteStatus(siteMap, "0000"); // 数据为空值
                            pollutionEmptyList.add(siteMap);
                        } else {
                            putSiteStatus(siteMap, "1111"); // 正常数据
                            pollutionList.add(siteMap);
                        }

                    }
                }
            }
            pollutionList.addAll(pollutionEmptyList);
            // 根据AvgStrength001字段排序
            Collections.sort(pollutionList, new Comparator<Map>() {
                @Override
                public int compare(Map b1, Map b2) {
                    if ("-".equals(b1.get("AvgStrength001")) && "-".equals(b2.get("AvgStrength001"))) {
                        return 0;
                    }
                    if ("-".equals(b1.get("AvgStrength001"))) {
                        return 1;
                    }
                    if ("-".equals(b2.get("AvgStrength001"))) {
                        return -1;
                    }
                    Double one = Double.valueOf(b1.get("AvgStrength001").toString()) * 100;
                    Double two = Double.valueOf(b2.get("AvgStrength001").toString()) * 100;
                    return (int) (two - one);
                }
            });

            for (Map<String, Object> siteInfo : siteInfoList) {
                if (!pollutionCodeList.contains(String.valueOf(siteInfo.get("siteCode")))) {
                    dealPollutionMap(siteInfo);
                    putSiteStatus(siteInfo, "0001"); // 无记录数据
                    pollutionList.add(siteInfo);
                }
            }

            returnList = pollutionList;
            // 扬尘
        } else if (SiteTypeEnum.RAISE_DUST_SITE.getValue().equals(pointType)) {
            Map<String, String> siteSnCodeMap = new HashMap<>();
            for (Map<String, Object> siteInfo : siteInfoList) {
                String monitorCode = (String) siteInfo.get("monitorCode");
                if ("1000".equals(monitorCode)) {
                    siteSnCodeMap.put(String.valueOf(siteInfo.get("siteCode")), String.valueOf(siteInfo.get("SNCode")));
                }
            }
            // 分钟数据
            List<Map<String, Object>> smallNewMinuteList = pollutionService
                .findPollutionMinuteNewDataBySNCodes(snCodeList);

            List<String> smallNewMinuteCodeList = new ArrayList<>();

            List<Map<String, Object>> smallNewMinuteMapList = new ArrayList<>();
            List<Map<String, Object>> smallNewMinuteEmptyList = new ArrayList<>();
            List<String> siteCodeEmptyList = new ArrayList<>();
            for (Map<String, Object> siteInfo : siteInfoList) {
                boolean flag = false;
                String siteCode = (String) siteInfo.get("siteCode");
                String snCode = (String) siteInfo.get("SNCode");
                if (smallNewMinuteCodeList.contains(siteCode)) {
                    continue;
                }
                // 把点位名称设置到查询出来的记录中
                for (Map<String, Object> hourPO : smallNewMinuteList) {
                    if (snCode.equals(hourPO.get("snCode"))) {
                        // 从数据库中读取的时间
                        String oragMonitorTime = hourPO.get("monitorTime").toString();
                        if (null != oragMonitorTime) {
                            hourPO.put("monitorTime", oragMonitorTime.substring(0, 16));
                        }
                        hourPO.put("siteName", siteInfo.get("siteName"));
                        hourPO.put("siteCode", siteInfo.get("siteCode"));
                        if (siteSnCodeMap.get(siteCode) != null) {
                            hourPO.put("SNCode", siteSnCodeMap.get(siteCode));
                        } else {
                            hourPO.put("SNCode", siteInfo.get("SNCode"));
                        }
                        hourPO.put("siteTypeCode", siteInfo.get("siteTypeCode"));
                        hourPO.put("Latitude", siteInfo.get("Latitude"));
                        hourPO.put("Longitude", siteInfo.get("Longitude"));
                        // 判断湿度、温度、风向、风力是否有值，无值默认实时天气数据
                        if ("0.0".equals(String.valueOf(hourPO.get("temp"))) || "0.0".equals(String.valueOf(hourPO.get("hum")))) {
                            setRealTimeWeather(hourPO, cityLiveWeatherMap);
                        } else {
                            hourPO.put("windDirection", WeatherUtil.changeAngleToWindDirectionWithEng(String.valueOf(hourPO.get("windDirection"))));
                            hourPO.put("windSpeed", WeatherUtil.changeWindSpeedToPowerNoCN(String.valueOf(hourPO.get("windSpeed"))));
                        }
                        if (!isOrNotExceptionData(hourPO)) {
                            smallNewMinuteCodeList.add(siteCode);
                            flag = true;
                            putSiteStatus(hourPO, "1111"); // 数据正常
                            // 结果集
                            smallNewMinuteMapList.add(hourPO);
                            break;
                        }
                    }
                }
                if (flag || siteCodeEmptyList.contains(snCode) || "1000".equals(siteInfo.get("monitorCode"))) {

                } else {
                    siteCodeEmptyList.add(snCode);
                    smallNewMinuteEmptyList.add(siteInfo);
                }

            }
            // 如果有无数据的
            if (siteCodeEmptyList.size() > 0) {
                // 小时数据
                List<Map<String, Object>> smallNewHourList = pollutionService
                    .findPollutionHourNewDataBySNCodes(siteCodeEmptyList);
                List<Map<String, Object>> hourEmptyList = new ArrayList<>();
                for (Map<String, Object> siteInfo : smallNewMinuteEmptyList) {
                    String siteCode = (String) siteInfo.get("siteCode");
                    String snCode = (String) siteInfo.get("SNCode");
                    boolean flag = false;
                    for (Map<String, Object> hourPO : smallNewHourList) {
                        if (snCode.equals(hourPO.get("snCode"))) {
                            hourPO.put("siteName", siteInfo.get("siteName"));
                            hourPO.put("siteCode", siteInfo.get("siteCode"));
                            if (siteSnCodeMap.get(siteCode) != null) {
                                hourPO.put("SNCode", siteSnCodeMap.get(siteCode));
                            } else {
                                hourPO.put("SNCode", siteInfo.get("SNCode"));
                            }
                            hourPO.put("siteTypeCode", siteInfo.get("siteTypeCode"));
                            hourPO.put("Latitude", siteInfo.get("Latitude"));
                            hourPO.put("Longitude", siteInfo.get("Longitude"));
                            // 判断湿度、温度、风向、风力是否有值，无值默认实时天气数据
                            if ("0.0".equals(String.valueOf(hourPO.get("temp"))) || "0.0".equals(String.valueOf(hourPO.get("hum")))) {
                                setRealTimeWeather(hourPO, cityLiveWeatherMap);
                            } else {
                                hourPO.put("windDirection", WeatherUtil.changeAngleToWindDirection(String.valueOf(hourPO.get("windDirection"))));
                                hourPO.put("windSpeed", WeatherUtil.changeWindSpeedToPower(String.valueOf(hourPO.get("windSpeed"))));
                            }
                            flag = true;
                            if (!isOrNotExceptionData(hourPO)) {
                                putSiteStatus(hourPO, "1111"); // 数据正常
                                // 结果集
                                smallNewMinuteMapList.add(hourPO);
                            } else {
                                dealHourPo(hourPO);
                                putSiteStatus(hourPO, "0000"); // 数据为空
                                hourEmptyList.add(hourPO);
                            }
                            break;
                        }
                    }
                    smallNewMinuteMapList.addAll(hourEmptyList);
                    if (!flag) {
                        dealHourPo(siteInfo);
                        putSiteStatus(siteInfo, "0001"); // 无记录数据
                        smallNewMinuteMapList.add(siteInfo);
                    }
                }
            }
            Collections.sort(smallNewMinuteMapList, (a, b) -> {
                if (null == a.get("pm10") && null == b.get("pm10")) {
                    return 0;
                }
                if ("-".equals(String.valueOf(a.get("pm10"))) && "-".equals(String.valueOf(b.get("pm10")))) {
                    return 0;
                }
                if (null == a.get("pm10") || "-".equals(String.valueOf(a.get("pm10")))) {
                    return 1;
                }
                if (null == b.get("pm10") || "-".equals(String.valueOf(b.get("pm10")))) {
                    return -1;
                }
                int one = Integer.valueOf(a.get("pm10").toString());
                int two = Integer.valueOf(b.get("pm10").toString());
                return (two - one);
            });
            returnList = smallNewMinuteMapList;

            // 工业废水
        } else if (SiteTypeEnum.WATER_POLLUTION_SITE.getValue().equals(pointType)) {

            List<Map> wpHourList = waterPollutionService
                .findWaterPollutionNewHourDataByPSCodeAndOutputCodes(siteCodeList);

            List<String> wpHourCodeList = new ArrayList<>();
            // 把有数据的点位返回给前端
            List<Map<String, Object>> haveDataList = new ArrayList<Map<String, Object>>();
            List<Map<String, Object>> noneDataList = new ArrayList<Map<String, Object>>();

            for (Map<String, Object> siteMap : siteInfoList) {
                String siteCode = (String) siteMap.get("siteCode");

                for (Map wpHourMap : wpHourList) {
                    String PSCode = wpHourMap.get("PSCode").toString();
                    if (siteCode.equals(PSCode)) {
                        if (wpHourCodeList.contains(siteCode)) {
                            continue;
                        }
                        wpHourCodeList.add(PSCode);
                        String monitorTime = wpHourMap.get("MONITORTIME").toString();
                        siteMap.put("monitorTime", monitorTime.substring(0, 16));

                        Object AvgStrength001 = wpHourMap.get("AvgStrength001");
                        AvgStrength001 = null == AvgStrength001 || "".equals(AvgStrength001) ? "-" : AvgStrength001;

                        Object AvgStrength002 = wpHourMap.get("AvgStrength002");
                        AvgStrength002 = null == AvgStrength002 || "".equals(AvgStrength002) ? "-" : AvgStrength002;

                        Object AvgStrength003 = wpHourMap.get("AvgStrength003");
                        AvgStrength003 = null == AvgStrength003 || "".equals(AvgStrength003) ? "-" : AvgStrength003;

                        Object CouFlow = wpHourMap.get("CouFlow");
                        CouFlow = null == CouFlow || "".equals(CouFlow) ? "-" : CouFlow;

                        siteMap.put("AvgStrength001", AvgStrength001);
                        siteMap.put("AvgStrength002", AvgStrength002);
                        siteMap.put("AvgStrength003", AvgStrength003);
                        siteMap.put("CouFlow", CouFlow);
                        if (isOrNotEmptyWPData(siteMap)) {
                            dealWaterPollutionMap(siteMap);
                            putSiteStatus(siteMap, "0000");
                            noneDataList.add(siteMap);
                        } else {
                            putSiteStatus(siteMap, "1111");
                            haveDataList.add(siteMap);
                        }
                        break;
                    }
                }

            }
            haveDataList.addAll(noneDataList);

            for (Map<String, Object> siteInfo : siteInfoList) {
                if (!wpHourCodeList.contains(String.valueOf(siteInfo.get("siteCode")))) {
                    dealWaterPollutionMap(siteInfo);
                    putSiteStatus(siteInfo, "0001"); // 未记录数据
                    haveDataList.add(siteInfo);
                }
            }

            // 根据CouFlow字段排序 (CouFlow字段已保证不为null)
            Collections.sort(haveDataList, new Comparator<Map>() {
                @Override
                public int compare(Map b1, Map b2) {
                    if ("-".equals(b1.get("CouFlow")) && "-".equals(b2.get("CouFlow"))) {
                        return 0;
                    }
                    if ("-".equals(b1.get("CouFlow"))) {
                        return 1;
                    }
                    if ("-".equals(b2.get("CouFlow"))) {
                        return -1;
                    }
                    Double one = Double.valueOf(b1.get("CouFlow").toString()) * 100;
                    Double two = Double.valueOf(b2.get("CouFlow").toString()) * 100;
                    return (int) (two - one);
                }
            });
            returnList = haveDataList;

            // 水质断面
        } else if (SiteTypeEnum.WATER_SURFACE_SITE.getValue().equals(pointType)) {

            List<Map> wsHourList = waterSurfaceService.findWaterSurfaceNewHourDataByPSCode(siteCodeList);

            // 把有数据的点位返回给前端
            List<Map<String, Object>> haveDataList = new ArrayList<Map<String, Object>>();
            List<Map<String, Object>> noneDataList = new ArrayList<Map<String, Object>>();

            List<String> haveCodeList = new ArrayList<>();

            for (Map<String, Object> siteMap : siteInfoList) {
                String siteCode = (String) siteMap.get("siteCode");
                for (Map wpHourMap : wsHourList) {
                    String PSCode = wpHourMap.get("SITECODE").toString();
                    if (siteCode.equals(PSCode)) {
                        haveCodeList.add(PSCode);
                        String monitorTime = wpHourMap.get("MONITORTIME").toString();
                        siteMap.put("monitorTime", monitorTime.substring(0, 16));
                        Object AvgStrength001 = wpHourMap.get("AvgStrength001");
                        AvgStrength001 = null == AvgStrength001 || "".equals(AvgStrength001) ? "-" : AvgStrength001;

                        Object AvgStrength002 = wpHourMap.get("AvgStrength002");
                        AvgStrength002 = null == AvgStrength002 || "".equals(AvgStrength002) ? "-" : AvgStrength002;

                        Object AvgStrength003 = wpHourMap.get("AvgStrength003");
                        AvgStrength003 = null == AvgStrength003 || "".equals(AvgStrength003) ? "-" : AvgStrength003;

                        Object AvgStrength004 = wpHourMap.get("AvgStrength004");
                        AvgStrength004 = null == AvgStrength004 || "".equals(AvgStrength004) ? "-" : AvgStrength004;

                        Object AvgStrength005 = wpHourMap.get("AvgStrength005");
                        AvgStrength005 = null == AvgStrength005 || "".equals(AvgStrength005) ? "-" : AvgStrength005;

                        Object AvgStrength013 = wpHourMap.get("AvgStrength013");
                        AvgStrength013 = null == AvgStrength013 || "".equals(AvgStrength013) ? "-" : AvgStrength013;

                        Object AvgStrength014 = wpHourMap.get("AvgStrength014");
                        AvgStrength014 = null == AvgStrength014 || "".equals(AvgStrength014) ? "-" : AvgStrength014;

                        Object AvgStrength015 = wpHourMap.get("AvgStrength015");
                        AvgStrength015 = null == AvgStrength015 || "".equals(AvgStrength015) ? "-" : AvgStrength015;

                        siteMap.put("AvgStrength001", AvgStrength001);
                        siteMap.put("AvgStrength002", AvgStrength002);
                        siteMap.put("AvgStrength003", AvgStrength003);
                        siteMap.put("AvgStrength004", AvgStrength004);
                        siteMap.put("AvgStrength005", AvgStrength005);
                        siteMap.put("AvgStrength013", AvgStrength013);
                        siteMap.put("AvgStrength014", AvgStrength014);
                        siteMap.put("AvgStrength015", AvgStrength015);
                        if (isOrNotEmptyWaterSurfaceData(siteMap)) {
                            dealWaterSurfaceMap(siteMap);
                            putSiteStatus(siteMap, "0000");
                            noneDataList.add(siteMap);
                        } else {
                            putSiteStatus(siteMap, "1111");
                            haveDataList.add(siteMap);
                        }
                        break;
                    }
                }

            }
            haveDataList.addAll(noneDataList);
            // 没有记录的数据
            for (Map<String, Object> siteInfo : siteInfoList) {
                if (!haveCodeList.contains(String.valueOf(siteInfo.get("siteCode")))) {
                    dealWaterSurfaceMap(siteInfo);
                    putSiteStatus(siteInfo, "0001");
                    haveDataList.add(siteInfo);
                }
            }
            returnList = haveDataList;

            // 油烟
        } else if (SiteTypeEnum.LAMPBLACK_SITE.getValue().equals(pointType)) {
            returnList = new ArrayList<Map<String, Object>>();
            Calendar calendar = Calendar.getInstance();

            List<Map<String, Object>> lampBlackList = lampBlackService.findLampBlackMinuteNewDataBySiteCodes(siteCodeList);

            List<String> haveSiteCodes = new ArrayList<>();
            for (Map<String, Object> siteMap : siteInfoList) {
                String siteCode = (String) siteMap.get("siteCode");

                for (Map<String, Object> lampBlack : lampBlackList) {
                    if (siteCode.equals(lampBlack.get("siteCode").toString())) {
                        if (haveSiteCodes.contains(siteCode)) {
                            continue;
                        }
                        haveSiteCodes.add(siteCode);

                        putSiteStatus(lampBlack, "1111"); // 正常数据
                        siteMap.putAll(lampBlack);
                        siteMap.computeIfAbsent("before", k -> setLampBlackData("1", cityLiveWeatherMap));
                        siteMap.computeIfAbsent("after", k -> setLampBlackData("2", cityLiveWeatherMap));
                        returnList.add(siteMap);
                    }
                }

            }
            for (Map<String, Object> siteMap : siteInfoList) {
//                Map<String, Object> before = (Map<String, Object>) siteMap.get("before");
//                if (null == before || null == before.get("concentration") || "".equals(before.get("concentration")) || "0".equals(before.get("concentration"))) {
//                    before = new HashMap<>();
//                    before.put("concentration", df.format(Math.random()));
//                    siteMap.put("before", before);
//                }
                if (!haveSiteCodes.contains(siteMap.get("siteCode").toString())) {
                    siteMap.computeIfAbsent("before", k -> setLampBlackData("1", cityLiveWeatherMap));
                    siteMap.computeIfAbsent("after", k -> setLampBlackData("2", cityLiveWeatherMap));
                    calendar.add(Calendar.MINUTE, -5);
                    String d = DateTimeUtil.getFormatDateStr(calendar.getTime(), DamConstant.ALL_SDF_YMD_HM).substring(0, 16);
                    String m = d.substring(15, 16);
                    if (Integer.valueOf(m) > 4) {
                        m = "5";
                    } else {
                        m = "0";
                    }
                    siteMap.put("monitorTime", d.substring(0, 15) + m);
                    putSiteStatus(siteMap, "1111");
                    returnList.add(siteMap);
                }
            }
            // 根据concentration字段排序
            Collections.sort(returnList, (b1, b2) -> {
                Map<String, Objects> before1 = (Map<String, Objects>) b1.get("before");
                Map<String, Objects> before2 = (Map<String, Objects>) b2.get("before");
                Double one = Double.valueOf(String.valueOf(before1.get("concentration"))) * 100;
                Double two = Double.valueOf(String.valueOf(before2.get("concentration"))) * 100;
                return (int) (two - one);
            });
            // 喷漆房
        } else if (SiteTypeEnum.SPRAY_BOOTH_SITE.getValue().equals(pointType)) {

            returnList = new ArrayList<Map<String, Object>>();
            Calendar calendar = Calendar.getInstance();

            Random random = new Random();

            for (Map<String, Object> siteMap : siteInfoList) {

                siteMap.put("concentration_before", random.nextInt(200) + 50);
                siteMap.put("concentration_after", random.nextInt(10) + 5);

                siteMap.put("monitorTime",
                    DateTimeUtil.getFormatDateStr(calendar.getTime(), DamConstant.ALL_SDF_YMD_H).substring(0, 16));
                putSiteStatus(siteMap, "1111");
                returnList.add(siteMap);
            }

            // 加油站
        } else if (SiteTypeEnum.GAS_STATION_SITE.getValue().equals(pointType)) {
            returnList = new ArrayList<Map<String, Object>>();
            Calendar calendar = Calendar.getInstance();

            Random random = new Random();

            for (Map<String, Object> siteMap : siteInfoList) {
                siteMap.put("concentration", df.format(random.nextDouble() * 5));
                siteMap.put("purifierState", "开");
                siteMap.put("blowerState", "开");
                siteMap.put("systemState", "正常");
                siteMap.put("conlimit", 2);
                siteMap.put("cleanLiness", "较清洁");
                siteMap.put("hum", 25.75);
                siteMap.put("temp", 22);
                siteMap.put("address", 1);
                siteMap.put("systemState", "正常");
                siteMap.put("monitorTime",
                    DateTimeUtil.getFormatDateStr(calendar.getTime(), DamConstant.ALL_SDF_YMD_H).substring(0, 16));
                putSiteStatus(siteMap, "1111");
                returnList.add(siteMap);
            }
        }

        Map<String, Object> returnMap = new HashMap<String, Object>();
        returnMap.put("siteList", returnList);        //返回的数据
        returnMap.put("centerSite", centerPointObj);  //中心城市点位
        returnMap.put("centerName", userRegionName);  //用户地图名称

        return returnMap;
    }

    public Map<String, Object> setLampBlackData(String addressType, Map<String, Object> cityLiveWeatherMap) {
        Map<String, Object> before = new HashMap<>();
        if (null == cityLiveWeatherMap) {
            before.put("hum", "-");
            before.put("temp", "-");
        } else {
            before.put("temp", null == cityLiveWeatherMap.get("temperature") ? "-" : cityLiveWeatherMap.get("temperature"));
            before.put("hum", null == cityLiveWeatherMap.get("humidity") ? "-" : cityLiveWeatherMap.get("humidity"));
        }
        before.put("concentration", df.format(Math.random()));
        before.put("purifierState", "开");
        before.put("blowerState", "开");
        before.put("systemState", "正常");
        before.put("conlimit", 2);
        before.put("cleanLiness", "较清洁");

        before.put("systemState", "正常");
        if ("1".equals(addressType)) {
            before.put("address", 1);
        }
        if ("2".equals(addressType)) {
            before.put("address", 2);
        }
        return before;
    }

    @SuppressWarnings({"unchecked", "rawtypes"})
    @Override
    public Map<String, Object> findCityLiveAQIByRegionCode(String regionCode) throws Exception {

        if (null == regionCode || "".equals(regionCode)) {
            // 根据登录用户，查询用户所属行政区域
            Map<String, Object> region = UserUtil.getRegion();
            regionCode = (String) region.get("regionCode");
        }

        /**
         * 区域编码查询区域信息
         */
        Map<String, Object> regionMap = regionSiteDao.findRegionInfoById(regionCode);

        // 数据库中的数据
//		Map cityLiveAQIMap = cityAirDao.fidCityLiveAQIByRegionCode(regionCode);
        RegionAirQualityPO cityLiveAQIMap = regionAirDao.findRegionLiveAQIByRegionCode(regionCode);

        // 转换为前端能识别的编码
        Map<String, Object> returnMap = new HashMap<String, Object>();

        returnMap.put("regionCode", cityLiveAQIMap.getREGIONCODE());
        returnMap.put("regionName", regionMap.get("regionName"));
        returnMap.put("aqiLevel", null == cityLiveAQIMap.getAQILEVEL() || Integer.valueOf(cityLiveAQIMap.getAQILEVEL()) <= 0 ? "-" : cityLiveAQIMap.getAQILEVEL());
        returnMap.put("aqiLevelType", null == cityLiveAQIMap.getAQILEVELTYPE() ? "-" : cityLiveAQIMap.getAQILEVELTYPE());
        returnMap.put("pollutant", cityLiveAQIMap.getPOLLUTANT());
        returnMap.put("aqi", null == cityLiveAQIMap.getAQI() || Integer.valueOf(cityLiveAQIMap.getAQI()) <= 0 ? "-" : cityLiveAQIMap.getAQI());
        returnMap.put("compositeValue", null == cityLiveAQIMap.getCOMPOSITEVALUE() || Double.valueOf(cityLiveAQIMap.getCOMPOSITEVALUE()) <= 0 ? "-" : cityLiveAQIMap.getCOMPOSITEVALUE());
        returnMap.put("pm10", cityLiveAQIMap.getPM10().getCONCENTRATION());
        returnMap.put("pm10IAQI", cityLiveAQIMap.getPM10().getIAQI());
        returnMap.put("pm25", cityLiveAQIMap.getPM25().getCONCENTRATION());
        returnMap.put("pm25IAQI", cityLiveAQIMap.getPM25().getIAQI());
        returnMap.put("so2", cityLiveAQIMap.getSO2().getCONCENTRATION());
        returnMap.put("so2IAQI", cityLiveAQIMap.getSO2().getIAQI());
        returnMap.put("no2", cityLiveAQIMap.getNO2().getCONCENTRATION());
        returnMap.put("no2IAQI", cityLiveAQIMap.getNO2().getIAQI());
        returnMap.put("co", cityLiveAQIMap.getCO().getCONCENTRATION());
        returnMap.put("coIAQI", cityLiveAQIMap.getCO().getIAQI());
        returnMap.put("o3", cityLiveAQIMap.getO3().getCONCENTRATION());
        returnMap.put("o3IAQI", cityLiveAQIMap.getO3().getIAQI());
        returnMap.put("monitorTime", cityLiveAQIMap.getMONITORTIME());

        return returnMap;
    }

    @SuppressWarnings("rawtypes")
    @Override
    public Map<String, Object> findAirSiteLastDetailListBySiteTypeForTrend(Map<String, Object> paraMap)
        throws Exception {

        /**
         * 国控点 nationalSite 省控点 provinceSite 小型站 smallAirSite 工业源 industrySite
         * 扬尘 raiseDustSite 油烟 lampblackSite 喷漆房 sprayBoothSite 加油站
         * gasStationSite 所有标准站 allNationalSite 所有空气站 allAirSite 所有污染源
         * allPollutionSite 所有站点 allSite
         *
         * 城市 citySite
         */
        String siteType = paraMap.get("siteType").toString();
        // 点位编码
        String siteCode = paraMap.get("siteCode").toString();

        List<Map<String, Object>> siteHourList = null;
        // 国控站、省控站 小型站
        if (SiteTypeEnum.NATIONAL_SITE.getValue().equals(siteType)
            || SiteTypeEnum.PROVINCE_SITE.getValue().equals(siteType)
            || SiteTypeEnum.CITY_SITE.getValue().equals(siteType)
            || SiteTypeEnum.SMALL_AIR_SITE.getValue().equals(siteType)) {
            siteHourList = gPoinAirService.findLast12HourGSiteHourDataBySiteCode(siteCode);
            // 城市
        } else if ("citySite".equals(siteType)) {
            siteHourList = findLast12HourCityHourDataBySiteCode(siteCode);
            // 工业源
        } else if (SiteTypeEnum.INDUSTRY_SITE.getValue().equals(siteType)) {

            List<String> siteCodeList = new ArrayList<String>();
            siteCodeList.add(siteCode);

            // 查询工业源 排口信息
            List<Map<String, Object>> outputInfoList = regionSiteDao.findIndustyOutputNameBySiteCode(siteCodeList);
            // 排口编号列表
            List<String> outputCodeList = new ArrayList<String>();
            for (Map<String, Object> outputMap : outputInfoList) {
                outputCodeList.add(String.valueOf(outputMap.get("outputCode")));
            }

            Map<String, Object> psDataMap = industryPollutionService
                .findLast12HourIndustyHourDataBySiteCodeForTrend(siteCode, outputCodeList);

            return psDataMap;

            // 扬尘
        } else if (SiteTypeEnum.RAISE_DUST_SITE.getValue().equals(siteType)) {
            siteHourList = smallAirService.findLast12HourRaiseDustHourDataBySiteCode(siteCode);
            JSONArray pm10List = new JSONArray();
            JSONArray pm25List = new JSONArray();
            JSONArray tempList = new JSONArray();
            JSONArray humList = new JSONArray();
            JSONArray wdList = new JSONArray();
            JSONArray wsList = new JSONArray();
            JSONArray timeList = new JSONArray();
            for (Map hourAirMap : siteHourList) {
                pm10List.add(hourAirMap.get("pm10"));
                pm25List.add(hourAirMap.get("pm25"));
                tempList.add(hourAirMap.get("temp"));
                humList.add(hourAirMap.get("hum"));
                wdList.add(hourAirMap.get("wd"));
                wsList.add(hourAirMap.get("ws"));
                Object monitorObj = hourAirMap.get("monitorTime");
                if (null == monitorObj) {
                    continue;
                }
                timeList.add(monitorObj.toString().substring(0, 16));
            }
            JSONObject dataObj = new JSONObject();
            dataObj.put("pm10", pm10List);
            dataObj.put("pm25", pm25List);
            dataObj.put("temp", tempList);
            dataObj.put("hum", humList);
            dataObj.put("wd", wdList);
            dataObj.put("ws", wsList);
            dataObj.put("time", timeList);
            return dataObj;
        } else if (SiteTypeEnum.WATER_POLLUTION_SITE.getValue().equals(siteType)) {
            // 工业废水
            List<PollutionIndustryEntity> waterHourList = waterPollutionService
                .findWaterPollutionLast12HourDataBySiteCode(siteCode);

            List<String> monitorTimeList = new ArrayList<String>();
            List<String> AvgStrength001List = new ArrayList<String>();
            List<String> AvgStrength002List = new ArrayList<String>();
            List<String> AvgStrength003List = new ArrayList<String>();

            for (PollutionIndustryEntity hourData : waterHourList) {
                String time = hourData.getMonitorTime();
                if (null == time || "".equals(time)) {
                    continue;
                }

                String avg001 = hourData.getAvgStrength001();
                avg001 = null == avg001 || "".equals(avg001) ? "-" : avg001;

                String avg002 = hourData.getAvgStrength002();
                avg002 = null == avg002 || "".equals(avg002) ? "-" : avg002;

                String avg003 = hourData.getAvgStrength003();
                avg003 = null == avg003 || "".equals(avg003) ? "-" : avg003;

                monitorTimeList.add(time.substring(0, 16));
                AvgStrength001List.add(avg001);
                AvgStrength002List.add(avg002);
                AvgStrength003List.add(avg003);
            }

            JSONObject dataObj = new JSONObject();
            dataObj.put("AvgStrength001", AvgStrength001List);
            dataObj.put("AvgStrength002", AvgStrength002List);
            dataObj.put("AvgStrength003", AvgStrength003List);
            dataObj.put("time", monitorTimeList);
            return dataObj;
        } else if (SiteTypeEnum.WATER_SURFACE_SITE.getValue().equals(siteType)) {
            // 水质断面
            List<WaterSurfaceEntity> waterHourList = waterSurfaceService
                .findWaterSurfaceLast12HourDataBySiteCode(siteCode);

            List<String> monitorTimeList = new ArrayList<String>();
            List<String> AvgStrength001List = new ArrayList<String>();
            List<String> AvgStrength002List = new ArrayList<String>();
            List<String> AvgStrength003List = new ArrayList<String>();
            List<String> AvgStrength004List = new ArrayList<String>();
            List<String> AvgStrength005List = new ArrayList<String>();
            List<String> AvgStrength013List = new ArrayList<String>();
            List<String> AvgStrength014List = new ArrayList<String>();
            List<String> AvgStrength015List = new ArrayList<String>();

            for (WaterSurfaceEntity hourData : waterHourList) {
                String time = hourData.getMonitorTime();
                if (null == time || "".equals(time)) {
                    continue;
                }
                String avg001 = hourData.getAvgStrength001();
                avg001 = null == avg001 || "".equals(avg001) ? "-" : avg001;

                String avg002 = hourData.getAvgStrength002();
                avg002 = null == avg002 || "".equals(avg002) ? "-" : avg002;

                String avg003 = hourData.getAvgStrength003();
                avg003 = null == avg003 || "".equals(avg003) ? "-" : avg003;

                String avg004 = hourData.getAvgStrength004();
                avg004 = null == avg004 || "".equals(avg004) ? "-" : avg004;

                String avg005 = hourData.getAvgStrength005();
                avg005 = null == avg005 || "".equals(avg005) ? "-" : avg005;

                String avg013 = hourData.getAvgStrength013();
                avg013 = null == avg013 || "".equals(avg013) ? "-" : avg013;

                String avg014 = hourData.getAvgStrength014();
                avg014 = null == avg014 || "".equals(avg014) ? "-" : avg014;

                String avg015 = hourData.getAvgStrength015();
                avg015 = null == avg015 || "".equals(avg015) ? "-" : avg015;

                monitorTimeList.add(time.substring(0, 16));
                AvgStrength001List.add(avg001);
                AvgStrength002List.add(avg002);
                AvgStrength003List.add(avg003);
                AvgStrength004List.add(avg004);
                AvgStrength005List.add(avg005);
                AvgStrength013List.add(avg013);
                AvgStrength014List.add(avg014);
                AvgStrength015List.add(avg015);
            }

            JSONObject dataObj = new JSONObject();
            dataObj.put("AvgStrength001", AvgStrength001List);
            dataObj.put("AvgStrength002", AvgStrength002List);
            dataObj.put("AvgStrength003", AvgStrength003List);
            dataObj.put("AvgStrength004", AvgStrength003List);
            dataObj.put("AvgStrength005", AvgStrength003List);
            dataObj.put("AvgStrength013", AvgStrength003List);
            dataObj.put("AvgStrength014", AvgStrength003List);
            dataObj.put("AvgStrength015", AvgStrength003List);
            dataObj.put("time", monitorTimeList);
            return dataObj;

            // 油烟
        } else if (SiteTypeEnum.LAMPBLACK_SITE.getValue().equals(siteType)) {
            // 查询油烟处理后的,12小时数据
            List<Map> lampBlackList = lampBlackDao.findLampBlack12HourDataBySiteCode(siteCode, 2);

            List<String> monitorTimeList = new ArrayList<String>();
            List<String> concentrationList = new ArrayList<String>();
            for (Map lampBlack : lampBlackList) {
                monitorTimeList.add((String) lampBlack.get("MONITORTIME"));
                concentrationList.add(lampBlack.get("CONCENTRATION") == null ? "-" : String.valueOf(lampBlack.get("CONCENTRATION")));
            }
//
//			for (int i = 12; i > 0; i--) {
//				calendar = Calendar.getInstance();
//				calendar.add(Calendar.HOUR_OF_DAY, -i);
//				monitorTimeList.add(DateTimeUtil.getFormatDateStr(calendar.getTime(), DamConstant.ALL_SDF_YMD_H));
//				concentrationList.add(df.format(Math.random()));
//			}

            JSONObject dataObj = new JSONObject();
            dataObj.put("concentration", concentrationList);
            dataObj.put("time", monitorTimeList);

            return dataObj;
            // 喷漆房
        } else if (SiteTypeEnum.SPRAY_BOOTH_SITE.getValue().equals(siteType)) {
            Calendar calendar = Calendar.getInstance();

            List<String> monitorTimeList = new ArrayList<String>();
            List<String> beforeList = new ArrayList<String>();
            List<String> afterList = new ArrayList<String>();

            Random random = new Random();

            for (int i = 12; i > 0; i--) {
                calendar = Calendar.getInstance();

                calendar.add(Calendar.HOUR_OF_DAY, -i);
                monitorTimeList.add(DateTimeUtil.getFormatDateStr(calendar.getTime(), DamConstant.ALL_SDF_YMD_H));
                beforeList.add(String.valueOf(random.nextInt(200) + 50));
                afterList.add(String.valueOf(random.nextInt(10) + 5));
            }

            JSONObject dataObj = new JSONObject();
            dataObj.put("concentrationBefore", beforeList);
            dataObj.put("concentrationAfter", afterList);
            dataObj.put("time", monitorTimeList);

            return dataObj;
            // 加油站
        } else if (SiteTypeEnum.GAS_STATION_SITE.getValue().equals(siteType)) {
            Calendar calendar = Calendar.getInstance();

            List<String> monitorTimeList = new ArrayList<String>();
            List<String> concentrationList = new ArrayList<String>();

            for (int i = 12; i > 0; i--) {
                calendar = Calendar.getInstance();
                calendar.add(Calendar.HOUR_OF_DAY, -i);
                monitorTimeList.add(DateTimeUtil.getFormatDateStr(calendar.getTime(), DamConstant.ALL_SDF_YMD_H));
                concentrationList.add(df.format(Math.random()));
            }

            JSONObject dataObj = new JSONObject();
            dataObj.put("concentration", concentrationList);
            dataObj.put("time", monitorTimeList);

            return dataObj;
        } else {
            return null;
        }

        List<String> aqiList = new ArrayList<String>();
        List<String> pm10List = new ArrayList<String>();
        List<String> pm25List = new ArrayList<String>();
        List<String> so2List = new ArrayList<String>();
        List<String> no2List = new ArrayList<String>();
        List<String> coList = new ArrayList<String>();
        List<String> o3List = new ArrayList<String>();
        List<String> monitorTimeList = new ArrayList<String>();

        for (Map<String, Object> dataMap : siteHourList) {
            Object monitorTimeObj = dataMap.get("monitorTime");
            if (null == monitorTimeObj || "".equals(monitorTimeObj)) {
                continue;
            }

            String monitorTime = monitorTimeObj.toString();
            // 时间格式化，把时间的秒去掉
            monitorTimeList.add(monitorTime.substring(0, 16));

            Object aqiObj = dataMap.get("aqi");
//            aqiObj = null == aqiObj || "".equals(aqiObj) ? "-" : aqiObj;
//            aqiList.add(aqiObj.toString());
            if (StringUtils.isEmpty(aqiObj) || !MathCalculateUtil.isInteger(aqiObj.toString()) || Integer.valueOf(aqiObj.toString()) < 0) {
                aqiList.add("-");
            } else {
                aqiList.add(aqiObj.toString());
            }

            Object pm10Obj = dataMap.get("pm10");
            pm10Obj = null == pm10Obj || "".equals(pm10Obj) ? "-" : pm10Obj;
            pm10List.add(pm10Obj.toString());

            Object pm25Obj = dataMap.get("pm25");
            pm25Obj = null == pm25Obj || "".equals(pm25Obj) ? "-" : pm25Obj;
            pm25List.add(pm25Obj.toString());

            Object so2Obj = dataMap.get("so2");
            so2Obj = null == so2Obj || "".equals(so2Obj) ? "-" : so2Obj;
            so2List.add(so2Obj.toString());

            Object no2Obj = dataMap.get("no2");
            no2Obj = null == no2Obj || "".equals(no2Obj) ? "-" : no2Obj;
            no2List.add(no2Obj.toString());

            Object coObj = dataMap.get("co");
            coObj = null == coObj || "".equals(coObj) ? "-" : coObj;
            coList.add(coObj.toString());

            Object o3Obj = dataMap.get("o3");
            o3Obj = null == o3Obj || "".equals(o3Obj) ? "-" : o3Obj;
            o3List.add(o3Obj.toString());
        }

        Map<String, Object> dataMap = new HashMap<String, Object>();
        dataMap.put("aqi", aqiList);
        dataMap.put("pm10", pm10List);
        dataMap.put("pm25", pm25List);
        dataMap.put("so2", so2List);
        dataMap.put("no2", no2List);
        dataMap.put("co", coList);
        dataMap.put("o3", o3List);
        dataMap.put("time", monitorTimeList);

        return dataMap;
    }

    // 数字保留两位小数
    DecimalFormat decimalformat = new DecimalFormat("######0.00");

    @SuppressWarnings({"unchecked", "rawtypes"})
    @Override
    public JSONArray findUserCityCurrentDayAQITotal() throws Exception {

        Calendar calendar = Calendar.getInstance();
        int curHour = calendar.get(Calendar.HOUR_OF_DAY);

        Map<String, Object> region = UserUtil.getRegion();
        String userRegionCode = (String) region.get("regionCode");

        // 查询参数
        CityAirParam cityAirParam = new CityAirParam();
        List<String> regionCodes = new ArrayList<String>();
        regionCodes.add(userRegionCode);
        cityAirParam.setRegionCodes(regionCodes);

        // 开始时间
        String startTime = DateTimeUtil.getFormatDateStr(calendar.getTime(), DamConstant.ALL_SDF_YMD);
        // 结束时间
        String endTime = DateTimeUtil.getFormatDateStr(calendar.getTime(), DamConstant.ALL_SDF_YMD_H);

        cityAirParam.setStartTime(startTime);
        cityAirParam.setEndTime(endTime);

        // 读取当天的24小时的小时数据，按照时间的倒序排列
//		List<Map> cityHourList = cityAirDao.findCityHourDataByRegionCodeAndTime(cityAirParam);
        List<RegionAirQualityPO> cityHourList = regionAirDao.findRegionHourDataByRegionCodesAndTime(cityAirParam);

        // 把数据按照时间的正序排列
        Collections.reverse(cityHourList);

        // 累计数据
        List<Map<String, Object>> cityHourTotalList = new ArrayList<Map<String, Object>>();

        int pm10sum = 0;
        int pm25sum = 0;
        int so2sum = 0;
        int no2sum = 0;
        double cosum = 0;
        int o3sum = 0;

        int index = 0;

        // 累计Map
        Map<String, Object> sumMap = null;
        // 计算每个小时的累计
        for (RegionAirQualityPO curHourDataMap : cityHourList) {
            sumMap = new HashMap<String, Object>();
            sumMap.put("MONITORTIME", curHourDataMap.getMONITORTIME());

            Object PM10Obj = curHourDataMap.getPM10().getCONCENTRATION();
            PM10Obj = null == PM10Obj || "".equals(PM10Obj) ? "0" : PM10Obj;
            pm10sum = pm10sum + Integer.valueOf(String.valueOf(PM10Obj));

            Object PM25Obj = curHourDataMap.getPM25().getCONCENTRATION();
            PM25Obj = null == PM25Obj || "".equals(PM25Obj) ? "0" : PM25Obj;
            pm25sum = pm25sum + Integer.valueOf(String.valueOf(PM25Obj));

            Object SO2Obj = curHourDataMap.getSO2().getCONCENTRATION();
            SO2Obj = null == SO2Obj || "".equals(SO2Obj) ? "0" : SO2Obj;
            so2sum = so2sum + Integer.valueOf(String.valueOf(SO2Obj));

            Object NO2Obj = curHourDataMap.getNO2().getCONCENTRATION();
            NO2Obj = null == NO2Obj || "".equals(NO2Obj) ? "0" : NO2Obj;
            no2sum = no2sum + Integer.valueOf(String.valueOf(NO2Obj));

            Object COObj = curHourDataMap.getCO().getCONCENTRATION();
            COObj = null == COObj || "".equals(COObj) ? "0" : COObj;
            cosum = cosum + Double.valueOf(String.valueOf(COObj));

            Object O3Obj = curHourDataMap.getO3().getCONCENTRATION();
            O3Obj = null == O3Obj || "".equals(O3Obj) ? "0" : O3Obj;
            o3sum = o3sum + Integer.valueOf(String.valueOf(O3Obj));

            index = index + 1;

            sumMap.put("PM10", Math.ceil(pm10sum / index));
            sumMap.put("PM25", Math.ceil(pm25sum / index));
            sumMap.put("SO2", Math.ceil(so2sum / index));
            sumMap.put("NO2", Math.ceil(no2sum / index));
            sumMap.put("CO", decimalformat.format(cosum / index));
            sumMap.put("O3", Math.ceil(o3sum / index));

            // 计算AQI
            int aqi = AQIProcess.getAqi(Integer.valueOf(Math.round(pm10sum / index)),
                Integer.valueOf(Math.round(pm25sum / index)), Integer.valueOf(Math.round(so2sum / index)),
                Integer.valueOf(Math.round(no2sum / index)), cosum / index,
                Integer.valueOf(Math.round(o3sum / index)));
            sumMap.put("AQI", aqi);

            cityHourTotalList.add(sumMap);
        }

        // 把数据按照时间的正序排序
        Collections.reverse(cityHourTotalList);

        // 实际aqi列表
        List<String> aqiList = new ArrayList<String>();
        // 预测aqi列表
        List<String> forcastAqiList = new ArrayList<String>();
        // 时间列表
        List<String> timeList = new ArrayList<String>();
        Random rand = new Random();

        boolean isHave = false;
        int forcastTime = curHour;
        for (int i = 0; i <= 23; i++) {
            timeList.add(String.valueOf(i));
            isHave = false;
            if (i <= forcastTime) {
                calendar = Calendar.getInstance();
                calendar.add(Calendar.HOUR_OF_DAY, -curHour);
                String time = DateTimeUtil.getFormatDateStr(calendar.getTime(), DamConstant.ALL_SDF_YMD_H);
                for (Map<String, Object> sumAqiMap : cityHourTotalList) {
                    if (time.equals(sumAqiMap.get("MONITORTIME"))) {
                        aqiList.add(String.valueOf(sumAqiMap.get("AQI")));
                        isHave = true;
                        break;
                    }
                }
                if (!isHave) {
                    aqiList.add("-");
                }

                curHour--;
            } else {
                aqiList.add("-");
            }

            // 预测数据，最简单的随机数。。。
            forcastAqiList.add(String.valueOf(rand.nextInt(105) + 55));
        }

        JSONArray aqiTotal = new JSONArray();
        aqiTotal.add(aqiList);
        aqiTotal.add(forcastAqiList);
        aqiTotal.add(timeList);
        return aqiTotal;
    }

    @SuppressWarnings({"unchecked", "rawtypes"})
    @Override
    public Map<String, Object> findCityCurrentComprehensiveIndexTotalForQJZL() throws Exception {

        // 获取登录用户所属区域信息
        Map<String, Object> region = UserUtil.getRegion();
        // 用户所属区域
        String userRegionCode = (String) region.get("regionCode");
        // 获取区域的类型
        String userRegionType = (String) region.get("regionType");

        JSONArray cityNameArr = new JSONArray();

        JSONArray outskirtsNameArr = new JSONArray();
        List<Map<String, Object>> regionSiteList;
        List<Map<String, Object>> officeList;
        List<String> cityCodeList = new ArrayList<>();
        List<String> outskirtsCodeList = new ArrayList<>();
        JSONObject nameObj = new JSONObject();
        Map<String, String> regionParamMap = new HashMap<>();
        if ("20".equals(userRegionType) || "24".equals(userRegionType)) {
            nameObj.put("cityName", "市区排名");
            nameObj.put("outskirtsName", "郊县排名");
            // 城市用户
            regionParamMap.put("sortScorpeType", "areaCountySort");
            if ("20".equals(userRegionType)) {
                regionParamMap.put("regionCode", userRegionCode);
            } else {
                regionParamMap.put("regionCode", region.get("parentCode").toString());
            }
            regionSiteList = regionSiteDao.findRegionListByRegionType(regionParamMap);
            for (Map regionMap : regionSiteList) {
                if ("22".equals(regionMap.get("regionType").toString())) {
                    cityNameArr.add(regionMap.get("regionName"));
                    cityCodeList.add(regionMap.get("regionCode").toString());
                } else if ("24".equals(regionMap.get("regionType").toString())
                    && !"航空港区".equals(regionMap.get("regionName"))) {
                    outskirtsNameArr.add(regionMap.get("regionName"));
                    outskirtsCodeList.add(regionMap.get("regionCode").toString());
                }
            }
        } else if ("22".equals(userRegionType)) {
            nameObj.put("cityName", "市区排名");
            nameObj.put("outskirtsName", "办事处排名");
            // 市区用户
            regionParamMap.put("sortScorpeType", "areaCountySort");
            regionParamMap.put("regionCode", region.get("parentCode").toString());
            // 查询出市区
            regionSiteList = regionSiteDao.findRegionListByRegionType(regionParamMap);
            for (Map regionMap : regionSiteList) {
                if ("22".equals(regionMap.get("regionType").toString())) {
                    cityNameArr.add(regionMap.get("regionName"));
                    cityCodeList.add(regionMap.get("regionCode").toString());
                }
            }
            regionParamMap.put("sortScorpeType", "officeSort");
            regionParamMap.put("regionCode", userRegionCode);
            // 查询办事处
            officeList = regionSiteDao.findRegionListByRegionType(regionParamMap);
            for (Map regionMap : officeList) {
                if ("30".equals(regionMap.get("regionType").toString())) {
                    outskirtsNameArr.add(regionMap.get("regionName"));
                    outskirtsCodeList.add(regionMap.get("regionCode").toString());
                }
            }
        }

        Map<String, Object> comprehensiveIndex = new HashMap<String, Object>();

        Map<String, Object> cityData = new HashMap<String, Object>();

        JSONArray cityDataArr = new JSONArray();

        Calendar calendar = Calendar.getInstance();
        // 查询参数
        CityAirParam cityAirParam = new CityAirParam();
        cityAirParam.setRegionCodes(cityCodeList);

        // 开始时间
        String startTime = DateTimeUtil.getFormatDateStr(calendar.getTime(), DamConstant.ALL_SDF_YMD);
        // 结束时间
        String endTime = DateTimeUtil.getFormatDateStr(calendar.getTime(), DamConstant.ALL_SDF_YMD_H);

        cityAirParam.setStartTime(startTime);
        cityAirParam.setEndTime(endTime);

        // 读取当天的24小时的小时数据，按照时间的倒序排列
//		List<Map> cityHourList = cityAirDao.findCityHourDataByRegionCodeAndTime(cityAirParam);
        List<RegionAirQualityPO> cityHourList = regionAirDao.findRegionHourDataByRegionCodesAndTime(cityAirParam);
        cityAirParam.setRegionCodes(outskirtsCodeList);

//		List<Map> outskirtsHourList = cityAirDao.findCityHourDataByRegionCodeAndTime(cityAirParam);
        List<RegionAirQualityPO> outskirtsHourList = regionAirDao.findRegionHourDataByRegionCodesAndTime(cityAirParam);

        Double cityAvg = 0.0;
        for (String cityCode : cityCodeList) {
            int pm10sum = 0;
            int pm25sum = 0;
            int so2sum = 0;
            int no2sum = 0;
            double cosum = 0;
            int o3sum = 0;

            int index = 0;
            for (RegionAirQualityPO curHourDataMap : cityHourList) {
                if (cityCode.equals(curHourDataMap.getREGIONCODE())) {
                    String PM10Obj = curHourDataMap.getPM10().getCONCENTRATION();
                    PM10Obj = null == PM10Obj || "".equals(PM10Obj) ? "0" : PM10Obj;
                    pm10sum = pm10sum + Integer.valueOf(String.valueOf(PM10Obj));

                    String PM25Obj = curHourDataMap.getPM25().getCONCENTRATION();
                    PM25Obj = null == PM25Obj || "".equals(PM25Obj) ? "0" : PM25Obj;
                    pm25sum = pm25sum + Integer.valueOf(String.valueOf(PM25Obj));

                    String SO2Obj = curHourDataMap.getSO2().getCONCENTRATION();
                    SO2Obj = null == SO2Obj || "".equals(SO2Obj) ? "0" : SO2Obj;
                    so2sum = so2sum + Integer.valueOf(String.valueOf(SO2Obj));

                    String NO2Obj = curHourDataMap.getNO2().getCONCENTRATION();
                    NO2Obj = null == NO2Obj || "".equals(NO2Obj) ? "0" : NO2Obj;
                    no2sum = no2sum + Integer.valueOf(String.valueOf(NO2Obj));

                    String COObj = curHourDataMap.getCO().getCONCENTRATION();
                    COObj = null == COObj || "".equals(COObj) ? "0" : COObj;
                    cosum = cosum + Double.valueOf(String.valueOf(COObj));

                    String O3Obj = curHourDataMap.getO3().getCONCENTRATION();
                    O3Obj = null == O3Obj || "".equals(O3Obj) ? "0" : O3Obj;
                    o3sum = o3sum + Integer.valueOf(String.valueOf(O3Obj));
                    index = index + 1;
                }
            }
            if (index == 0) {
                cityDataArr.add("-");
            } else {
                String comprehensiveIndexStr = AQIProcess.getComprehensiveIndex(
                    Integer.valueOf(Math.round(pm10sum / index)), Integer.valueOf(Math.round(pm25sum / index)),
                    Integer.valueOf(Math.round(so2sum / index)), Integer.valueOf(Math.round(no2sum / index)),
                    cosum / index, Integer.valueOf(Math.round(o3sum / index)));
                cityDataArr.add(comprehensiveIndexStr);
                cityAvg += Double.valueOf(comprehensiveIndexStr);
            }
        }
        cityAvg = cityAvg / cityCodeList.size();
        // 组装数据排序
        // 组装数据排序
        List<Map<String, Object>> cityDataList = new ArrayList<>();
        for (int i = 0; i < cityDataArr.size(); i++) {
            Map<String, Object> map = new HashMap<>();
            map.put("data", cityDataArr.get(i));
            map.put("name", cityNameArr.get(i));
            cityDataList.add(map);
        }

        Collections.sort(cityDataList, new Comparator() {
            public int compare(Object a, Object b) {
                if ("-".equals(((Map) a).get("data").toString())) {
                    return 1;
                }
                if ("-".equals(((Map) b).get("data").toString())) {
                    return -1;
                }
                Double one = Double.valueOf(((Map) a).get("data").toString()) * 100;
                Double two = Double.valueOf(((Map) b).get("data").toString()) * 100;
                return (int) (two - one);
            }
        });
        cityNameArr = new JSONArray();
        cityDataArr = new JSONArray();
        for (Map cityDataMap : cityDataList) {
            cityNameArr.add(cityDataMap.get("name"));
            cityDataArr.add(cityDataMap.get("data"));
        }

        cityData.put("nameList", cityNameArr);
        cityData.put("dataList", cityDataArr);
        cityData.put("dataAVG", cityAvg);

        Map<String, Object> outskirtsData = new HashMap<String, Object>();

        JSONArray outskirtsDataArr = new JSONArray();

        Double outskirtsAvg = 0.0;
        for (String outskirtsCode : outskirtsCodeList) {
            int pm10sum = 0;
            int pm25sum = 0;
            int so2sum = 0;
            int no2sum = 0;
            double cosum = 0;
            int o3sum = 0;

            int index = 0;
            for (RegionAirQualityPO curHourDataMap : outskirtsHourList) {
                if (outskirtsCode.equals(curHourDataMap.getREGIONCODE())) {
                    String PM10Obj = curHourDataMap.getPM10().getCONCENTRATION();
                    PM10Obj = null == PM10Obj || "".equals(PM10Obj) ? "0" : PM10Obj;
                    pm10sum = pm10sum + Integer.valueOf(String.valueOf(PM10Obj));

                    String PM25Obj = curHourDataMap.getPM25().getCONCENTRATION();
                    PM25Obj = null == PM25Obj || "".equals(PM25Obj) ? "0" : PM25Obj;
                    pm25sum = pm25sum + Integer.valueOf(String.valueOf(PM25Obj));

                    String SO2Obj = curHourDataMap.getSO2().getCONCENTRATION();
                    SO2Obj = null == SO2Obj || "".equals(SO2Obj) ? "0" : SO2Obj;
                    so2sum = so2sum + Integer.valueOf(String.valueOf(SO2Obj));

                    String NO2Obj = curHourDataMap.getNO2().getCONCENTRATION();
                    NO2Obj = null == NO2Obj || "".equals(NO2Obj) ? "0" : NO2Obj;
                    no2sum = no2sum + Integer.valueOf(String.valueOf(NO2Obj));

                    String COObj = curHourDataMap.getCO().getCONCENTRATION();
                    COObj = null == COObj || "".equals(COObj) ? "0" : COObj;
                    cosum = cosum + Double.valueOf(String.valueOf(COObj));

                    String O3Obj = curHourDataMap.getO3().getCONCENTRATION();
                    O3Obj = null == O3Obj || "".equals(O3Obj) ? "0" : O3Obj;
                    o3sum = o3sum + Integer.valueOf(String.valueOf(O3Obj));
                    index = index + 1;
                }
            }
            if (index == 0) {
                outskirtsDataArr.add("-");
            } else {
                String comprehensiveIndexStr = AQIProcess.getComprehensiveIndex(
                    Integer.valueOf(Math.round(pm10sum / index)), Integer.valueOf(Math.round(pm25sum / index)),
                    Integer.valueOf(Math.round(so2sum / index)), Integer.valueOf(Math.round(no2sum / index)),
                    cosum / index, Integer.valueOf(Math.round(o3sum / index)));
                outskirtsDataArr.add(comprehensiveIndexStr);
                outskirtsAvg += Double.valueOf(comprehensiveIndexStr);
            }

        }

        outskirtsAvg = outskirtsAvg / outskirtsCodeList.size();
        // 组装数据排序
        // 组装数据排序
        List<Map<String, Object>> outskirtsDataList = new ArrayList<>();
        for (int i = 0; i < outskirtsDataArr.size(); i++) {
            Map<String, Object> map = new HashMap<>();
            map.put("data", outskirtsDataArr.get(i));
            map.put("name", outskirtsNameArr.get(i));
            outskirtsDataList.add(map);
        }

        Collections.sort(outskirtsDataList, new Comparator() {
            public int compare(Object a, Object b) {
                if ("-".equals(((Map) a).get("data").toString())) {
                    return 1;
                }
                if ("-".equals(((Map) b).get("data").toString())) {
                    return -1;
                }
                Double one = Double.valueOf(((Map) a).get("data").toString()) * 100;
                Double two = Double.valueOf(((Map) b).get("data").toString()) * 100;
                return (int) (two - one);
            }
        });
        outskirtsDataArr = new JSONArray();
        outskirtsNameArr = new JSONArray();
        for (Map cityDataMap : outskirtsDataList) {
            outskirtsNameArr.add(cityDataMap.get("name"));
            outskirtsDataArr.add(cityDataMap.get("data"));
        }

        outskirtsData.put("nameList", outskirtsNameArr);
        outskirtsData.put("dataList", outskirtsDataArr);
        outskirtsData.put("dataAVG", outskirtsAvg);

        comprehensiveIndex.put("tabName", nameObj);
        comprehensiveIndex.put("cityData", cityData);
        comprehensiveIndex.put("outskirtsData", outskirtsData);

        return comprehensiveIndex;
    }

    @SuppressWarnings({"rawtypes", "unchecked"})
    @Override
    public Map<String, Object> findCityRankings() throws Exception {
        // 获取登录用户所属区域信息
        Map<String, Object> region = UserUtil.getRegion();
        // 用户所属区域
        String userRegionCode = (String) region.get("regionCode");
        // 获取区域的类型
        String userRegionType = (String) region.get("regionType");
        Map<String, String> regionParamMap = new HashMap<>();
        List<Map<String, Object>> regionSiteList;
        List<String> regionCodeList = new ArrayList<>();
        JSONArray nameList = new JSONArray();
        System.out.println("userRegionType = " + userRegionType);
        if ("10".equals(userRegionType)) {
            nameList.add("省内城市");
            // 省内排名
            regionParamMap.put("sortScorpeType", "provinceSort");
            regionParamMap.put("regionCode", region.get("regionCode").toString());
            regionSiteList = regionSiteDao.findRegionListByRegionType(regionParamMap);
            for (Map regionSite : regionSiteList) {
                if ("20".equals(regionSite.get("regionType").toString())) {
                    regionCodeList.add(regionSite.get("regionCode").toString());
                }
            }
        }
        if ("20".equals(userRegionType)) {
            nameList.add("省内城市");
            // 城市 省内排名
            regionParamMap.put("sortScorpeType", "provinceSort");
            regionParamMap.put("regionCode", region.get("parentCode").toString());
            regionSiteList = regionSiteDao.findRegionListByRegionType(regionParamMap);
            for (Map regionSite : regionSiteList) {
                if ("20".equals(regionSite.get("regionType").toString())) {
                    regionCodeList.add(regionSite.get("regionCode").toString());
                }
            }
        } else if ("22".equals(userRegionType)) {
            nameList.add("市区排名");
            // 市区 市区排名
            regionParamMap.put("sortScorpeType", "areaCountySort");
            regionParamMap.put("regionCode", region.get("parentCode").toString());
            regionSiteList = regionSiteDao.findRegionListByRegionType(regionParamMap);
            for (Map regionSite : regionSiteList) {
                if ("22".equals(regionSite.get("regionType").toString())) {
                    regionCodeList.add(regionSite.get("regionCode").toString());
                }
            }
        } else if ("24".equals(userRegionType)) {
            nameList.add("郊县排名");
            // 郊县 郊县排名
            regionParamMap.put("sortScorpeType", "areaCountySort");
            regionParamMap.put("regionCode", region.get("parentCode").toString());
            regionSiteList = regionSiteDao.findRegionListByRegionType(regionParamMap);
            for (Map regionSite : regionSiteList) {
                if ("24".equals(regionSite.get("regionType").toString())) {
                    regionCodeList.add(regionSite.get("regionCode").toString());
                }
            }
        }
        Calendar yearCalender = Calendar.getInstance();
        SimpleDateFormat sdf3 = new SimpleDateFormat(DamConstant.ALL_SDF_YMD);
        yearCalender.add(Calendar.DATE, -1);
        String startTime = sdf3.format(yearCalender.getTime());
        CityAirParam cityAirParam = new CityAirParam();
        cityAirParam.setRegionCodes(regionCodeList);
        cityAirParam.setStartTime(startTime);
        cityAirParam.setEndTime(startTime);
//		List<Map> cityDayList = cityAirDao.findCityDayDataByRegionCodeAndTime(cityAirParam);
        List<RegionAirQualityPO> cityDayList = regionAirDao.findRegionDayDataByRegionCodesAndTime(cityAirParam);
        int index = 0;
        for (RegionAirQualityPO cityDay : cityDayList) {
            if (userRegionCode.equals(cityDay.getREGIONCODE())) {
                break;
            }
            index++;
        }
        JSONObject dayRank = new JSONObject();
        dayRank.put("rank", cityDayList.size() - index == 0 ? "-" : cityDayList.size() - index);
        dayRank.put("count", regionCodeList.size());

//        List<Map> cityMonthList = cityAirDao.findCityMonthByRegionCodeAndTime(cityAirParam);
        List<RegionAirQualityPO> cityMonthList = regionAirDao.findRegionMonthDataByRegionCodesAndTime(cityAirParam);
        int mIndex = 0;
        for (RegionAirQualityPO cityMonth : cityMonthList) {
            if (userRegionCode.equals(cityMonth.getREGIONCODE())) {
                break;
            }
            mIndex++;
        }
        JSONObject monthRank = new JSONObject();
        monthRank.put("rank", cityMonthList.size() - mIndex == 0 ? "-" : cityMonthList.size() - mIndex);
        monthRank.put("count", regionCodeList.size());

//        List<Map> cityYearList = cityAirDao.findCityYearByRegionCodeAndTime(cityAirParam);
        List<RegionAirQualityPO> cityYearList = regionAirDao.findRegionYearDataByRegionCodesAndTime(cityAirParam);

        int yIndex = 0;
        for (RegionAirQualityPO cityYear : cityYearList) {
            if (userRegionCode.equals(cityYear.getREGIONCODE())) {
                break;
            }
            yIndex++;
        }
        JSONObject yearRank = new JSONObject();
        yearRank.put("rank", cityYearList.size() - yIndex == 0 ? "-" : cityYearList.size() - yIndex);
        yearRank.put("count", regionCodeList.size());
        JSONObject rankObj = new JSONObject();
        rankObj.put("dayRank", dayRank);
        rankObj.put("monthRank", monthRank);
        rankObj.put("yearRank", yearRank);

        // 城市综合指数排名
        JSONObject dayChange = new JSONObject();
        JSONObject monthChange = new JSONObject();
        JSONObject yearChange = new JSONObject();

        dayChange.put("change", "6");
        dayChange.put("count", regionCodeList.size());
        monthChange.put("change", "8");
        monthChange.put("count", regionCodeList.size());
        yearChange.put("change", "5");
        yearChange.put("count", regionCodeList.size());

        JSONObject changeObj = new JSONObject();
        changeObj.put("dayChange", dayChange);
        changeObj.put("monthChange", monthChange);
        changeObj.put("yearChange", yearChange);

        nameList.add("74城市");
        nameList.add("2+26城市");

        // 74城市综合指数排名
        JSONObject rank74 = new JSONObject();
        JSONObject dayRank74 = new JSONObject();
        JSONObject monthRank74 = new JSONObject();
        JSONObject yearRank74 = new JSONObject();
        dayRank74.put("rank", "12");
        dayRank74.put("count", "74");

        monthRank74.put("rank", "8");
        monthRank74.put("count", "74");

        yearRank74.put("rank", "15");
        yearRank74.put("count", "74");

        rank74.put("dayRank", dayRank74);
        rank74.put("monthRank", monthRank74);
        rank74.put("yearRank", yearRank74);

        // 74城市变化程度
        JSONObject change74 = new JSONObject();
        JSONObject dayChange74 = new JSONObject();
        JSONObject monthChange74 = new JSONObject();
        JSONObject yearChange74 = new JSONObject();
        dayChange74.put("change", "12");
        dayChange74.put("count", "74");

        monthChange74.put("change", "8");
        monthChange74.put("count", "74");

        yearChange74.put("change", "15");
        yearChange74.put("count", "74");

        change74.put("dayChange", dayChange74);
        change74.put("monthChange", monthChange74);
        change74.put("yearChange", yearChange74);

        // 2+26城市综合指数排名
        JSONObject rank2_26 = new JSONObject();
        JSONObject dayRank2_26 = new JSONObject();
        JSONObject monthRank2_26 = new JSONObject();
        JSONObject yearRank2_26 = new JSONObject();
        dayRank2_26.put("rank", "12");
        dayRank2_26.put("count", "28");

        monthRank2_26.put("rank", "8");
        monthRank2_26.put("count", "28");

        yearRank2_26.put("rank", "15");
        yearRank2_26.put("count", "28");

        rank2_26.put("dayRank", dayRank2_26);
        rank2_26.put("monthRank", monthRank2_26);
        rank2_26.put("yearRank", yearRank2_26);

        // 2+26城市综合指数变化程度
        JSONObject change2_26 = new JSONObject();
        JSONObject dayChange2_26 = new JSONObject();
        JSONObject monthChange2_26 = new JSONObject();
        JSONObject yearChange2_26 = new JSONObject();
        dayChange2_26.put("change", "12");
        dayChange2_26.put("count", "28");

        monthChange2_26.put("change", "8");
        monthChange2_26.put("count", "28");

        yearChange2_26.put("change", "15");
        yearChange2_26.put("count", "28");

        change2_26.put("dayChange", dayChange2_26);
        change2_26.put("monthChange", monthChange2_26);
        change2_26.put("yearChange", yearChange2_26);

        // 数据组装
        JSONArray rankList = new JSONArray();
        rankList.add(rankObj);
        rankList.add(rank74);
        rankList.add(rank2_26);

        JSONArray changeList = new JSONArray();
        changeList.add(changeObj);
        changeList.add(change74);
        changeList.add(change2_26);

        JSONObject resultObj = new JSONObject();
        resultObj.put("nameList", nameList);
        resultObj.put("rankList", rankList);
        resultObj.put("changeList", changeList);

        return resultObj;
    }

    /**
     * 当前登录用户74城市排名
     *
     * @return
     * @throws Exception
     */

    @SuppressWarnings({"rawtypes", "unchecked"})
    @Override
    public Map<String, Object> find74CityRanking(Map<String, Object> paramMap) throws Exception {
        String order = (String) paramMap.get("order");

        // 获取登录用户所属区域信息
        Map<String, Object> region = UserUtil.getRegion();
        // 用户所属区域
        String userRegionCode = (String) region.get("regionCode");
        // 获取区域的类型
        String userRegionType = (String) region.get("regionType");


        List<Map<String, Object>> regionInfoList;
        List<String> regionCodeList = new ArrayList<>();

        String cityCode = "";
        /**
         * 根据当前登录用户区域，查询该区域的上级区域
         */
        List<Map<String, Object>> parentRegionList = regionSiteDao.findParentRegionInfoByRegionCode(userRegionCode);
        // 把登录用户所属省份、和市编码，读取出来
        for (Map<String, Object> parentRegionMap : parentRegionList) {
            String retionType = String.valueOf(parentRegionMap.get("regionType"));
            if ("20".equals(retionType)) {
                cityCode = String.valueOf(parentRegionMap.get("regionCode"));
            }
        }
        if (null == cityCode) {
            cityCode = userRegionCode;
        }
        Map<String, String> regionParamMap = new HashMap<>();
        regionParamMap.put("sortScorpeType", "seventyFourCitySort");
        regionParamMap.put("rankingType", "74city");
        regionInfoList = regionSiteDao.findRegionListByRankingType(regionParamMap);
        regionCodeList.clear();
        for (Map<String, Object> regionMap : regionInfoList) {
            regionCodeList.add(regionMap.get("regionCode").toString());
        }

        Calendar yearCalender = Calendar.getInstance();
        SimpleDateFormat sdf3 = new SimpleDateFormat(DamConstant.ALL_SDF_YMD);
        yearCalender.add(Calendar.DATE, -1);
        String startTime = sdf3.format(yearCalender.getTime());

        CityAirParam cityAirParam = new CityAirParam();
        cityAirParam.setRegionCodes(regionCodeList);
        cityAirParam.setStartTime(startTime);
        cityAirParam.setEndTime(startTime);

        List<RegionAirQualityPO> hourList = regionAirDao.findRegionRealHourDataByRegionCodes(cityAirParam);
        List<RegionAirQualityPO> cityDayList = regionAirDao.findRegionDayDataByRegionCodesAndTime(cityAirParam);
        List<RegionAirQualityPO> cityMonthList = regionAirDao.findRegionMonthDataByRegionCodesAndTime(cityAirParam);
        List<RegionAirQualityPO> cityYearList = regionAirDao.findRegionYearDataByRegionCodesAndTime(cityAirParam);
        // 实时AQI排名
        Collections.sort(hourList, (a, b) -> {
            if (null == a.getAQI() && null == b.getAQI()) {
                return 0;
            }
            if (null == a.getAQI()) {
                return 1;
            }
            if (null == b.getAQI()) {
                return -1;
            }
            Double one = Double.valueOf(a.getAQI());
            Double two = Double.valueOf(b.getAQI());
            return (int) (two - one);
        });
        int index = 0;
        for (RegionAirQualityPO cityHour : hourList) {
            if (userRegionCode.equals(cityHour.getREGIONCODE())) {
                break;
            }
            index++;
        }

        JSONObject realRank74 = new JSONObject();
        if ("severse".equals(order)) {
            realRank74.put("rank", hourList.size() - index == 0 ? "-" : index + 1);
        } else {
            realRank74.put("rank", hourList.size() - index == 0 ? "-" : hourList.size() - index);
        }

        realRank74.put("count", regionCodeList.size());

        // 昨日排名
        int dIndex = 0;
        for (RegionAirQualityPO cityDay : cityDayList) {
            if (userRegionCode.equals(cityDay.getREGIONCODE())) {
                break;
            }
            dIndex++;
        }
        JSONObject dayRank74 = new JSONObject();
        if ("severse".equals(order)) {
            dayRank74.put("rank", cityDayList.size() - dIndex == 0 ? "-" : dIndex + 1);
        } else {
            dayRank74.put("rank", cityDayList.size() - dIndex == 0 ? "-" : cityDayList.size() - dIndex);
        }
        dayRank74.put("count", regionCodeList.size());

        // 月排名
        int mIndex = 0;
        for (RegionAirQualityPO cityMonth : cityMonthList) {
            if (cityCode.equals(cityMonth.getREGIONCODE())) {
                break;
            }
            mIndex++;
        }
        JSONObject monthRank74 = new JSONObject();
        if ("severse".equals(order)) {
            monthRank74.put("rank", cityMonthList.size() - mIndex == 0 ? "-" : mIndex + 1);
        } else {
            monthRank74.put("rank", cityMonthList.size() - mIndex == 0 ? "-" : cityMonthList.size() - mIndex);
        }
        monthRank74.put("count", regionCodeList.size());

        // 年排名
        int yIndex = 0;
        for (RegionAirQualityPO cityYear : cityYearList) {
            if (cityCode.equals(cityYear.getREGIONCODE())) {
                break;
            }
            yIndex++;
        }
        JSONObject yearRank74 = new JSONObject();
        if ("severse".equals(order)) {
            yearRank74.put("rank", cityYearList.size() - yIndex == 0 ? "-" : yIndex + 1);
        } else {
            yearRank74.put("rank", cityYearList.size() - yIndex == 0 ? "-" : cityYearList.size() - yIndex);
        }
        yearRank74.put("count", regionCodeList.size());

        // 74城市综合指数排名
        JSONArray nameList = new JSONArray();
        nameList.add("74城市");

        JSONObject rank74 = new JSONObject();
        rank74.put("realRank74", realRank74);
        rank74.put("dayRank", dayRank74);
        rank74.put("monthRank", monthRank74);
        rank74.put("yearRank", yearRank74);

        JSONObject resultObj = new JSONObject();
        resultObj.put("rank74List", rank74);

        return resultObj;
    }

    @SuppressWarnings("unchecked")
    @Override
    public Map<String, Object> findGpointAQIByMapLevel(Map<String, Object> paraMap) throws Exception {

        // 获取登录用户所属区域信息
        Map<String, Object> region = UserUtil.getRegion();
        // 用户所属区域
        String userRegionCode = (String) region.get("regionCode");
        // 获取区域的类型
        // String userRegionType = (String) region.get("regionType");

        // 查询区域或者站点 的条件
        Map<String, String> siteParaMap = null;

        // 返回给前端展示的列表
        List<Map<String, Object>> returnList = null;
//        siteParaMap = new HashMap<String, String>();
//        siteParaMap.put("regionCode", userRegionCode);
//        siteParaMap.put("siteType", "nationalSite");
        RegionSiteParam siteParam = new RegionSiteParam();
        siteParam.setSiteType("nationalSite");
        siteParam.setRegionCode(userRegionCode);
        List<Map<String, Object>> siteInfoList = regionSiteDao.findSiteInfoByRegionCodeAndSiteType(siteParam);
        // 点位编码
        List<String> siteCodeList = new ArrayList<String>();
        for (Map<String, Object> siteMap : siteInfoList) {
            siteCodeList.add(String.valueOf(siteMap.get("siteCode")));
        }

        List<Map<String, Object>> pointNewDataList = gPoinAirService
            .findGPointNewMinuteDataBySiteCodeList(siteCodeList);

        List<String> pointNewDataCodeList = new ArrayList<>();
        List<Map<String, Object>> pointNewDataMapList = new ArrayList<>();
        List<Map<String, Object>> pointEmptyDataList = new ArrayList<>();
        // 把点位名称设置到查询出来的记录中
        for (Map<String, Object> hourPO : pointNewDataList) {
            // 如果已经有数据,跳过
            if (pointNewDataCodeList.contains(String.valueOf(hourPO.get("siteCode")))) {
                continue;
            }
            pointNewDataCodeList.add(String.valueOf(hourPO.get("siteCode")));
            // 从数据库中读取的时间
            String oragMonitorTime = hourPO.get("monitorTime").toString();
            if (null != oragMonitorTime) {
                hourPO.put("monitorTime", oragMonitorTime.substring(0, 16));
            }
            String hourSiteCode = hourPO.get("siteCode").toString();
            for (Map<String, Object> siteMap : siteInfoList) {
                String siteCode = (String) siteMap.get("siteCode");
                if (siteCode.equals(hourSiteCode)) {
                    hourPO.put("siteName", siteMap.get("siteName"));
                    hourPO.put("siteTypeCode", siteMap.get("siteTypeCode"));
                    hourPO.put("Latitude", siteMap.get("Latitude"));
                    hourPO.put("Longitude", siteMap.get("Longitude"));
                    hourPO.put("temp", "-");
                    hourPO.put("hum", "-");
                    hourPO.put("windDirection", "西南风");
                    hourPO.put("windSpeed", "3级");
                    break;
                }
            }
            // 判断是否是全部为0的无效数据
            boolean flag = isOrNotEmptyData(hourPO);
            if (flag) {
                hourPO.put("siteStatus", "0000"); // 无效数据
                dealHourPo(hourPO);
                pointEmptyDataList.add(hourPO);
            } else {
                hourPO.put("siteStatus", "1111"); // 有效数据
                pointNewDataMapList.add(hourPO);
            }
        }

        pointNewDataMapList.addAll(pointEmptyDataList);

        for (Map<String, Object> siteMap : siteInfoList) {
            if (!pointNewDataCodeList.contains(String.valueOf(siteMap.get("siteCode")))) {
                dealHourPo(siteMap);
                siteMap.put("monitorTime", "-");
                siteMap.put("temp", "-");
                siteMap.put("hum", "-");
                siteMap.put("windDirection", "-");
                siteMap.put("windSpeed", "-");
                putSiteStatus(siteMap, "0001"); // 无记录数据
                pointNewDataMapList.add(siteMap);
            }
        }

        // 返回的数据
        returnList = pointNewDataMapList;
        String userRegionName = (String) region.get("regionName");

        /**
         * 根据当前登录用户区域，查询该区域的上级区域
         */
        List<Map<String, Object>> parentRegionList = regionSiteDao.findParentRegionInfoByRegionCode(userRegionCode);

        // 地图的中心点位
        JSONObject centerPointObj = new JSONObject();
        for (Map<String, Object> parentRegionMap : parentRegionList) {
            String regionCode = String.valueOf(parentRegionMap.get("regionCode"));
            if (userRegionCode.equals(regionCode)) {
                centerPointObj.put("lng", parentRegionMap.get("longitude"));
                centerPointObj.put("lat", parentRegionMap.get("latitude"));
            }
        }

        Map<String, Object> returnMap = new HashMap<String, Object>();
        returnMap.put("siteList", returnList);
        returnMap.put("centerSite", centerPointObj);
        returnMap.put("centerName", userRegionName);

        return returnMap;
    }

    @Override
    public Map<String, Object> findHotPointData(Map<String, Object> paramMap) throws Exception {
        String regionCode = (String) paramMap.get("regionCode");
        String siteType = (String) paramMap.get("siteType");
        String searchTime = (String) paramMap.get("searchTime");
        String siteTypeCode = (String) paramMap.get("siteTypeCode");
        RegionSiteParam siteParam = new RegionSiteParam();
        siteParam.setRegionCode(regionCode);
        siteParam.setSiteType(siteType);
        siteParam.setSiteTypeCodeList(Arrays.asList(siteTypeCode.split(",")));

        List<Map<String, Object>> siteInfoList = regionSiteDao.findSiteInfoByRegionCodeAndSiteType(siteParam);
        List<String> siteCodeList = new ArrayList<>();
        for (Map<String, Object> siteInfo : siteInfoList) {
            siteCodeList.add((String) siteInfo.get("siteCode"));
        }
//        CityAirParam cityAirParam = new CityAirParam();
//        cityAirParam.setRegionCodes(regionCodeList);
//        cityAirParam.setStartTime(paramMap.get("startTime").toString());
//        cityAirParam.setEndTime(paramMap.get("endTime").toString());
//        // 查询全国城市小时数据
//        List<RegionAirQualityPO> cityHourDataList = regionAirDao.findRegionHourDataByRegionCodesAndTime(cityAirParam);
        SiteAirParam siteAirParam = new SiteAirParam();
        siteAirParam.setSiteCodes(siteCodeList);
        siteAirParam.setStartTime(searchTime);
        siteAirParam.setEndTime(searchTime);
        List<SiteAirQualityPO> siteAirQualityPOList = siteAirDao.findSiteAirHourDataBySiteCodesAndTime(siteAirParam);
        JSONArray resultList = new JSONArray();
        for (Map<String, Object> siteInfo : siteInfoList) {
            for (SiteAirQualityPO siteAir : siteAirQualityPOList) {
                JSONObject returnMap = new JSONObject();
                if (siteInfo.get("siteCode") != null && siteInfo.get("siteCode").toString().equals(siteAir.getSITECODE())) {
                    dealFactorIntegerData(returnMap, siteAir.getAQI(), "AQI");
                    dealFactorIntegerData(returnMap, siteAir.getPM10().getCONCENTRATION(), "PM10");
                    dealFactorIntegerData(returnMap, siteAir.getPM25().getCONCENTRATION(), "PM2_5");
                    dealFactorIntegerData(returnMap, siteAir.getSO2().getCONCENTRATION(), "SO2");
                    dealFactorIntegerData(returnMap, siteAir.getNO2().getCONCENTRATION(), "NO2");
                    dealFactorIntegerData(returnMap, siteAir.getO3().getCONCENTRATION(), "O3");
                    dealFactorDoubleData(returnMap, siteAir.getCO().getCONCENTRATION(), "CO");
                    returnMap.put("lng", siteInfo.get("Longitude"));
                    returnMap.put("lat", siteInfo.get("Latitude"));
                    resultList.add(returnMap);
                }

            }
        }

        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("hotPointList", resultList);

        return resultMap;
    }


    public void dealFactorIntegerData(JSONObject objArr, String factor, String factorName) {
        if (StringUtils.isEmpty(factor) || !MathCalculateUtil.isInteger(factor) || Integer.valueOf(factor) < 0) {
            objArr.put(factorName, "0");
        } else {
            objArr.put(factorName, factor);
        }
    }

    public void dealFactorDoubleData(JSONObject objArr, String factor, String factorName) {
        if (StringUtils.isEmpty(factor) || !MathCalculateUtil.isNumeric(factor) || Double.valueOf(factor) < 0) {
            objArr.put(factorName, "0");
        } else {
            objArr.put(factorName, factor);
        }
    }

    @SuppressWarnings({"rawtypes", "unchecked"})
    @Override
    public Map<String, Object> findNationalSiteAQIByMapLevel(Map<String, Object> paraMap) throws Exception {

        /**
         *
         * 区域级别 areaLevel： 338个市级城市 cityLevel; 338个市级城市和直管县 cityCountyLevel;
         * 全国国控点位 nationalSiteLevel;
         *
         */
        String areaLevel = paraMap.get("areaLevel").toString();

        // 查询区域或者站点 的条件
        Map<String, String> siteParaMap = null;

        // 返回给前端展示的列表
        List<Map<String, Object>> returnList = null;

        // 全国国控点
        if ("nationalSiteLevel".equals(areaLevel)) {
//            siteParaMap = new HashMap<String, String>();
//            siteParaMap.put("siteType", "allNationalSite");
            RegionSiteParam siteParam = new RegionSiteParam();
            siteParam.setSiteType("allNationalSite");
            List<Map<String, Object>> siteInfoList = regionSiteDao.findSiteInfoByRegionCodeAndSiteType(siteParam);

            // 点位编码
            List<String> siteCodeList = new ArrayList<String>();
            for (Map<String, Object> siteMap : siteInfoList) {
                siteCodeList.add(String.valueOf(siteMap.get("siteCode")));
            }

            List<Map<String, Object>> pointNewDataList = gPoinAirService
                .findGPointNewMinuteDataBySiteCode(siteCodeList);

            List<String> pointNewDataCodeList = new ArrayList<>();
            List<Map<String, Object>> pointNewDataMapList = new ArrayList<>();
            List<Map<String, Object>> pointEmptyDataList = new ArrayList<>();
            // 把点位名称设置到查询出来的记录中
            for (Map<String, Object> hourPO : pointNewDataList) {
                pointNewDataCodeList.add(String.valueOf(hourPO.get("siteCode")));

                // 从数据库中读取的时间
                String oragMonitorTime = hourPO.get("monitorTime").toString();
                if (null != oragMonitorTime) {
                    hourPO.put("monitorTime", oragMonitorTime.substring(0, 16));
                }
                String hourSiteCode = hourPO.get("siteCode").toString();
                for (Map<String, Object> siteMap : siteInfoList) {
                    String siteCode = (String) siteMap.get("siteCode");
                    if (siteCode.equals(hourSiteCode)) {
                        hourPO.put("siteName", siteMap.get("siteName"));
                        hourPO.put("siteTypeCode", siteMap.get("siteTypeCode"));
                        hourPO.put("Latitude", siteMap.get("Latitude"));
                        hourPO.put("Longitude", siteMap.get("Longitude"));
                        hourPO.put("temp", "-");
                        hourPO.put("hum", "-");
                        hourPO.put("windDirection", "西南风");
                        hourPO.put("windSpeed", "3级");
                    }
                }
                // 判断是否是全部为0的无效数据
                boolean flag = isOrNotEmptyData(hourPO);
                if (flag) {
                    hourPO.put("siteStatus", "0000"); // 无效数据
                    dealHourPo(hourPO);
                    pointEmptyDataList.add(hourPO);
                } else {
                    hourPO.put("siteStatus", "1111"); // 有效数据
                    pointNewDataMapList.add(hourPO);
                }
            }
            pointNewDataMapList.addAll(pointEmptyDataList);

            for (Map<String, Object> siteMap : siteInfoList) {
                if (!pointNewDataCodeList.contains(String.valueOf(siteMap.get("siteCode")))) {
                    dealHourPo(siteMap);
                    siteMap.put("monitorTime", "-");
                    siteMap.put("temp", "-");
                    siteMap.put("hum", "-");
                    siteMap.put("windDirection", "-");
                    siteMap.put("windSpeed", "-");
                    putSiteStatus(siteMap, "0001"); // 无记录数据
                    pointNewDataMapList.add(siteMap);
                }
            }

            // 返回的数据
            returnList = pointNewDataMapList;

            // 全国城市及直管县
        } else if ("cityCountyLevel".equals(areaLevel)) {
            siteParaMap = new HashMap<String, String>();
            siteParaMap.put("sortScorpeType", "cityCountySort");
            List<Map<String, Object>> cityInfoList = regionSiteDao.findRegionListByRegionType(siteParaMap);

            // 区域编码列表
            List<String> regionCodeList = new ArrayList<String>();
            for (Map<String, Object> siteMap : cityInfoList) {
                regionCodeList.add(String.valueOf(siteMap.get("regionCode")));
            }

//            List<Map> cityNewDataList = cityAirDao.findCityNewHourDataByRegionCodes(regionCodeList);
            List<RegionAirQualityPO> cityNewDataList = regionAirDao.findRegionHourDataByRegionCodes(regionCodeList);


            returnList = convertCityAQI(cityInfoList, cityNewDataList);

            // 全国城市
        } else if ("cityLevel".equals(areaLevel)) {
            siteParaMap = new HashMap<String, String>();
            siteParaMap.put("sortScorpeType", "nationalSort");
            List<Map<String, Object>> cityInfoList = regionSiteDao.findRegionListByRegionType(siteParaMap);

            // 区域编码列表
            List<String> regionCodeList = new ArrayList<String>();
            for (Map<String, Object> siteMap : cityInfoList) {
                regionCodeList.add(String.valueOf(siteMap.get("regionCode")));
            }

//            List<Map> cityNewDataList = cityAirDao.findCityNewHourDataByRegionCodes(regionCodeList);
            List<RegionAirQualityPO> cityNewDataList = regionAirDao.findRegionHourDataByRegionCodes(regionCodeList);

            returnList = convertCityAQI(cityInfoList, cityNewDataList);
        } else {
            return null;
        }

        Map<String, Object> region = UserUtil.getRegion();
        String userRegionCode = (String) region.get("regionCode");
        String userRegionName = (String) region.get("regionName");

        /**
         * 根据当前登录用户区域，查询该区域的上级区域
         */
        List<Map<String, Object>> parentRegionList = regionSiteDao.findParentRegionInfoByRegionCode(userRegionCode);

        // 地图的中心点位
        JSONObject centerPointObj = new JSONObject();
        for (Map<String, Object> parentRegionMap : parentRegionList) {
            String regionCode = String.valueOf(parentRegionMap.get("regionCode"));
            if (userRegionCode.equals(regionCode)) {
                centerPointObj.put("lng", parentRegionMap.get("longitude"));
                centerPointObj.put("lat", parentRegionMap.get("latitude"));
            }
        }

        Map<String, Object> returnMap = new HashMap<String, Object>();
        returnMap.put("siteList", returnList);
        returnMap.put("centerSite", centerPointObj);
        returnMap.put("centerName", userRegionName);

        return returnMap;
    }

    /**
     * 把城市AQI转换为 地图可以 读取的格式 主要是 字段名称，注意大小写
     *
     * @param cityInfoList
     * @param cityNewDataList
     * @return
     */
    @SuppressWarnings("rawtypes")
    public List<Map<String, Object>> convertCityAQI(List<Map<String, Object>> cityInfoList,
                                                    List<RegionAirQualityPO> cityNewDataList) {
        // 初始化 返回的数据列表
        List<Map<String, Object>> returnList = new ArrayList<Map<String, Object>>();
        List<Map<String, Object>> returnEmptyList = new ArrayList<Map<String, Object>>();

        List<String> cityCodeList = new ArrayList<>();
        Map<String, Object> tempDataMap = null;
        // 把点位名称设置到查询出来的记录中
        for (RegionAirQualityPO hourMap : cityNewDataList) {
            tempDataMap = new HashMap<String, Object>();

            // 从数据库中读取的时间
            String oragMonitorTime = hourMap.getMONITORTIME();
            tempDataMap.put("monitorTime", oragMonitorTime.substring(0, 16));
            tempDataMap.put("aqi", hourMap.getAQI());
            tempDataMap.put("aqiLevel", hourMap.getAQILEVEL());
            tempDataMap.put("compositeValue", hourMap.getCOMPOSITEVALUE());
            tempDataMap.put("pollutant", hourMap.getPOLLUTANT());
            tempDataMap.put("aqiLevelType", hourMap.getAQILEVELTYPE());
            tempDataMap.put("pm10", hourMap.getPM10().getCONCENTRATION());
            tempDataMap.put("pm10IAQI", hourMap.getPM10().getIAQI());
            tempDataMap.put("pm25", hourMap.getPM25().getCONCENTRATION());
            tempDataMap.put("pm25IAQI", hourMap.getPM25().getIAQI());
            tempDataMap.put("so2", hourMap.getSO2().getCONCENTRATION());
            tempDataMap.put("so2IAQI", hourMap.getSO2().getIAQI());
            tempDataMap.put("no2", hourMap.getNO2().getCONCENTRATION());
            tempDataMap.put("no2IAQI", hourMap.getNO2().getIAQI());
            tempDataMap.put("co", hourMap.getCO().getCONCENTRATION());
            tempDataMap.put("coIAQI", hourMap.getCO().getIAQI());
            tempDataMap.put("o3", hourMap.getO3().getCONCENTRATION());
            tempDataMap.put("o3IAQI", hourMap.getO3().getIAQI());

            String hourRegionCode = hourMap.getREGIONCODE();
            cityCodeList.add(hourRegionCode);
            for (Map<String, Object> siteMap : cityInfoList) {
                String regionCode = (String) siteMap.get("regionCode");
                if (regionCode.equals(hourRegionCode)) {
                    tempDataMap.put("siteCode", regionCode);
                    tempDataMap.put("siteName", siteMap.get("regionName"));
                    tempDataMap.put("siteTypeCode", "citySite");
                    tempDataMap.put("Latitude", siteMap.get("latitude"));
                    tempDataMap.put("Longitude", siteMap.get("longitude"));
                    tempDataMap.put("temp", "-");
                    tempDataMap.put("hum", "-");
                    tempDataMap.put("windDirection", "西南风");
                    tempDataMap.put("windSpeed", "3级");
                }
            }
            if (isOrNotEmptyData(tempDataMap)) {
                dealHourPo(tempDataMap);
                putSiteStatus(tempDataMap, "0000");
                returnEmptyList.add(tempDataMap);
            } else {
                putSiteStatus(tempDataMap, "1111");
                returnList.add(tempDataMap);

            }
        }
        returnList.addAll(returnEmptyList);
        for (Map<String, Object> siteMap : cityInfoList) {
            if (!cityCodeList.contains(String.valueOf(siteMap.get("regionCode")))) {
                tempDataMap = new HashMap<>();
                dealHourPo(tempDataMap);
                tempDataMap.put("siteCode", String.valueOf(siteMap.get("regionCode")));
                tempDataMap.put("siteName", siteMap.get("regionName"));
                tempDataMap.put("siteTypeCode", "citySite");
                tempDataMap.put("Latitude", siteMap.get("latitude"));
                tempDataMap.put("Longitude", siteMap.get("longitude"));
                putSiteStatus(tempDataMap, "0001");
                returnList.add(tempDataMap);
            }
        }

        return returnList;
    }

    @SuppressWarnings("rawtypes")
    @Override
    public List<Map<String, Object>> findLast12HourCityHourDataBySiteCode(String regionCode) {

//		List<Map> cityHourList = cityAirDao.findLast12HourCityHourDataBySiteCode(regionCode);
        List<RegionAirQualityPO> cityHourList = regionAirDao.findRegionHour12DataByRegionCode(regionCode);
        List<Map<String, Object>> aqiList = new ArrayList<Map<String, Object>>();
        Map<String, Object> aqiMap = null;
        for (RegionAirQualityPO hourAirMap : cityHourList) {
            aqiMap = new HashMap<String, Object>();
            aqiMap.put("aqi", hourAirMap.getAQI() == null || Double.valueOf(hourAirMap.getAQI()) <= 0 ? "-" : hourAirMap.getAQI());
            aqiMap.put("aqiLevel", hourAirMap.getAQILEVEL());
            aqiMap.put("aqiLevelType", hourAirMap.getAQILEVELTYPE());
            aqiMap.put("pollutant", hourAirMap.getPOLLUTANT());
            aqiMap.put("compositeValue", hourAirMap.getCOMPOSITEVALUE() == null || Double.valueOf(hourAirMap.getCOMPOSITEVALUE()) <= 0 ? "-" : hourAirMap.getCOMPOSITEVALUE());

            aqiMap.put("pm10", hourAirMap.getPM10().getCONCENTRATION());

            aqiMap.put("pm25", hourAirMap.getPM25().getCONCENTRATION());

            aqiMap.put("so2", hourAirMap.getSO2().getCONCENTRATION());

            aqiMap.put("no2", hourAirMap.getNO2().getCONCENTRATION());

            aqiMap.put("co", hourAirMap.getCO().getCONCENTRATION());

            aqiMap.put("o3", hourAirMap.getO3().getCONCENTRATION());

//			aqiMap.put("siteCode", hourAirMap.get("SITECODE"));
            aqiMap.put("regionCode", hourAirMap.getREGIONCODE());
            aqiMap.put("monitorTime", hourAirMap.getMONITORTIME());

            aqiList.add(aqiMap);
        }

        return aqiList;
    }

    /**
     * 判断标准站中的数据是否全部为0
     *
     * @param hourPO
     * @return
     */
    @SuppressWarnings("rawtypes")
    public boolean isOrNotEmptyData(Map hourPO) {
        String aqi = String.valueOf(hourPO.get("aqi"));
        String pm10IAQI = String.valueOf(hourPO.get("pm10IAQI"));
        String pm10 = String.valueOf(hourPO.get("pm10"));
        String pm25 = String.valueOf(hourPO.get("pm25"));
        String pm25IAQI = String.valueOf(hourPO.get("pm25IAQI"));
        String co = String.valueOf(hourPO.get("co"));
        String coIAQI = String.valueOf(hourPO.get("coIAQI"));
        String no2 = String.valueOf(hourPO.get("no2"));
        String no2IAQI = String.valueOf(hourPO.get("no2IAQI"));
        String so2 = String.valueOf(hourPO.get("so2"));
        String so2IAQI = String.valueOf(hourPO.get("so2IAQI"));
        String o3 = String.valueOf(hourPO.get("o3"));
        String o3IAQI = String.valueOf(hourPO.get("o3IAQI"));
        String compositeValue = String.valueOf(hourPO.get("compositeValue"));

        return isEmpty(aqi) && isEmpty(pm10IAQI) && isEmpty(pm10) && isEmpty(pm25) && isEmpty(pm25IAQI) && isEmpty(co)
            && isEmpty(coIAQI) && isEmpty(no2) && isEmpty(no2IAQI) && isEmpty(so2) && isEmpty(so2IAQI)
            && isEmpty(o3) && isEmpty(o3IAQI) && isEmpty(compositeValue);
    }

    /**
     * 判断标准站中的数据是否全部为0
     *
     * @param hourPO
     * @return
     */
    @SuppressWarnings("rawtypes")
    public boolean isOrNotExceptionData(Map hourPO) {
        String aqi = String.valueOf(hourPO.get("aqi"));
        String pm10IAQI = String.valueOf(hourPO.get("pm10IAQI"));
        String pm10 = String.valueOf(hourPO.get("pm10"));
        String pm25 = String.valueOf(hourPO.get("pm25"));
        String pm25IAQI = String.valueOf(hourPO.get("pm25IAQI"));
        String co = String.valueOf(hourPO.get("co"));
        String coIAQI = String.valueOf(hourPO.get("coIAQI"));
        String no2 = String.valueOf(hourPO.get("no2"));
        String no2IAQI = String.valueOf(hourPO.get("no2IAQI"));
        String so2 = String.valueOf(hourPO.get("so2"));
        String so2IAQI = String.valueOf(hourPO.get("so2IAQI"));
        String o3 = String.valueOf(hourPO.get("o3"));
        String o3IAQI = String.valueOf(hourPO.get("o3IAQI"));
        String compositeValue = String.valueOf(hourPO.get("compositeValue"));
        String hum = String.valueOf(hourPO.get("hum"));
        String temp = String.valueOf(hourPO.get("temp"));
        String windDirection = String.valueOf(hourPO.get("windDirection"));
        String windSpeed = String.valueOf(hourPO.get("windSpeed"));

        return isEmpty(aqi) && isEmpty(pm10IAQI) && isEmpty(pm10) && isEmpty(pm25) && isEmpty(pm25IAQI) && isEmpty(co)
            && isEmpty(coIAQI) && isEmpty(no2) && isEmpty(no2IAQI) && isEmpty(so2) && isEmpty(so2IAQI)
            && isEmpty(o3) && isEmpty(o3IAQI) && isEmpty(compositeValue) && isEmpty(hum) && isEmpty(temp)
            && isEmpty(windDirection) && isEmpty(windSpeed);
    }

    /**
     * 是否是异常数据
     *
     * @param hourPO
     * @return
     */
    public boolean isOrNotInvalidAqiData(Map hourPO) {
        String aqi = String.valueOf(hourPO.get("aqi"));
        String compositeValue = String.valueOf(hourPO.get("compositeValue"));
        return (Double.valueOf(aqi) <= 0 && Double.valueOf(compositeValue) <= 0);

    }

    /**
     * 判断工业源中的数据是否全部为0
     *
     * @param pollution
     * @return
     */
    @SuppressWarnings("rawtypes")
    public boolean isOrNotEmptyPollutionData(Map pollution) {
        String AvgStrength001 = String.valueOf(pollution.get("AvgStrength001"));
        String AvgStrength002 = String.valueOf(pollution.get("AvgStrength002"));
        String AvgStrength003 = String.valueOf(pollution.get("AvgStrength003"));
        String AvgZsStrength003 = String.valueOf(pollution.get("AvgZsStrength003"));
        String AvgZsStrength002 = String.valueOf(pollution.get("AvgZsStrength002"));
        String AvgZsStrength001 = String.valueOf(pollution.get("AvgZsStrength001"));

        return isEmpty(AvgStrength001) && isEmpty(AvgStrength002) && isEmpty(AvgStrength003) && isEmpty(AvgZsStrength003)
            && isEmpty(AvgZsStrength002) && isEmpty(AvgZsStrength001);

    }

    /**
     * 判断工业废水中的数据是否全部为0
     *
     * @param pollution
     * @return
     */
    @SuppressWarnings("rawtypes")
    public boolean isOrNotEmptyWPData(Map pollution) {
        String AvgStrength001 = String.valueOf(pollution.get("AvgStrength001"));
        String AvgStrength002 = String.valueOf(pollution.get("AvgStrength002"));
        String AvgStrength003 = String.valueOf(pollution.get("AvgStrength003"));
        String PFL001 = String.valueOf(pollution.get("PFL001"));
        String PFL002 = String.valueOf(pollution.get("PFL002"));
        String PFL003 = String.valueOf(pollution.get("PFL003"));
        String CouFlow = String.valueOf(pollution.get("CouFlow"));
        String AvgFlow = String.valueOf(pollution.get("AvgFlow"));

        return isEmpty(AvgStrength001) && isEmpty(AvgStrength002) && isEmpty(AvgStrength003) && isEmpty(PFL001)
            && isEmpty(PFL002) && isEmpty(PFL003) && isEmpty(CouFlow) && isEmpty(AvgFlow);

    }

    /**
     * 判断水质断面中的数据是否全部为0
     *
     * @param pollution
     * @return
     */
    @SuppressWarnings("rawtypes")
    public boolean isOrNotEmptyWaterSurfaceData(Map pollution) {
        String AvgStrength001 = String.valueOf(pollution.get("AvgStrength001"));
        String AvgStrength002 = String.valueOf(pollution.get("AvgStrength002"));
        String AvgStrength003 = String.valueOf(pollution.get("AvgStrength003"));
        String AvgStrength004 = String.valueOf(pollution.get("AvgStrength004"));
        String AvgStrength005 = String.valueOf(pollution.get("AvgStrength005"));
        String AvgStrength013 = String.valueOf(pollution.get("AvgStrength013"));
        String AvgStrength014 = String.valueOf(pollution.get("AvgStrength014"));
        String AvgStrength015 = String.valueOf(pollution.get("AvgStrength015"));

        return isEmpty(AvgStrength001) && isEmpty(AvgStrength002) && isEmpty(AvgStrength003) && isEmpty(AvgStrength004)
            && isEmpty(AvgStrength005) && isEmpty(AvgStrength013) && isEmpty(AvgStrength014)
            && isEmpty(AvgStrength015);

    }

    public boolean isEmpty(String str) {
        return null == str || "-".equals(str) || "0".equals(str) || "0.0".equals(str) || "0.00".equals(str);
    }

    @SuppressWarnings({"rawtypes", "unchecked"})
    public void dealWaterPollutionMap(Map waterPollution) {
        waterPollution.put("monitorTime", "-");
        waterPollution.put("AvgStrength001", "-");
        waterPollution.put("AvgStrength002", "-");
        waterPollution.put("AvgStrength003", "-");
        waterPollution.put("PFL001", "-");
        waterPollution.put("PFL002", "-");
        waterPollution.put("PFL003", "-");
        waterPollution.put("CouFlow", "-");
        waterPollution.put("AvgFlow", "-");
    }

    @SuppressWarnings({"unchecked", "rawtypes"})
    public void dealWaterSurfaceMap(Map waterPollution) {
        waterPollution.put("AvgStrength001", "-");
        waterPollution.put("AvgStrength002", "-");
        waterPollution.put("AvgStrength003", "-");
        waterPollution.put("AvgStrength004", "-");
        waterPollution.put("AvgStrength005", "-");
        waterPollution.put("AvgStrength013", "-");
        waterPollution.put("AvgStrength014", "-");
        waterPollution.put("AvgStrength015", "-");
        waterPollution.put("monitorTime", "-");
    }

    @SuppressWarnings({"rawtypes", "unchecked"})
    public void dealPollutionMap(Map pollution) {
        pollution.put("monitorTime", "-");
        pollution.put("AvgStrength001", "-");
        pollution.put("AvgStrength002", "-");
        pollution.put("AvgStrength003", "-");
        pollution.put("AvgZsStrength003", "-");
        pollution.put("AvgZsStrength002", "-");
        pollution.put("AvgZsStrength001", "-");
    }

    @SuppressWarnings({"rawtypes", "unchecked"})
    public void dealHourPo(Map hourPO) {
        hourPO.put("aqi", "-");
        hourPO.put("pm10IAQI", "-");
        hourPO.put("pm10", "-");
        hourPO.put("pm25", "-");
        hourPO.put("pm25IAQI", "-");
        hourPO.put("co", "-");
        hourPO.put("coIAQI", "-");
        hourPO.put("no2", "-");
        hourPO.put("no2IAQI", "-");
        hourPO.put("so2", "-");
        hourPO.put("so2IAQI", "-");
        hourPO.put("o3", "-");
        hourPO.put("o3IAQI", "-");
        hourPO.put("compositeValue", "-");
        hourPO.put("aqiLevel", "-");
        hourPO.put("aqiLevelType", "-");
        hourPO.put("pollutant", "-");
        hourPO.put("windDirection", "-");
        hourPO.put("hum", "-");
        hourPO.put("temp", "-");
        hourPO.put("windSpeed", "-");
        hourPO.put("monitorTime", "-");
    }

    /**
     * status :
     * 1111 正常数据
     * 0000 异常数据(数据库有,但是未0的数据)
     * 0001 未记录数据(数据库没有的数据)
     *
     * @param map
     * @param status
     */
    @SuppressWarnings({"unchecked", "rawtypes"})
    public void putSiteStatus(Map map, String status) {
        map.put("siteStatus", status);
    }

    /**
     * 判断市天气实时数据是否为空，有值赋值；无则默认“-”
     *
     * @param hourPO
     * @param cityLiveWeatherMap
     */
    public void setRealTimeWeather(Map<String, Object> hourPO, Map cityLiveWeatherMap) {

        if (null == cityLiveWeatherMap) {
            hourPO.put("temp", "-");
            hourPO.put("hum", "-");
            hourPO.put("windDirection", "-");
            hourPO.put("windSpeed", "-");
        } else {
            hourPO.put("temp", null == cityLiveWeatherMap.get("temperature") ? "-" : cityLiveWeatherMap.get("temperature"));
            hourPO.put("hum", null == cityLiveWeatherMap.get("humidity") ? "-" : cityLiveWeatherMap.get("humidity"));
            if (StringUtils.isEmpty(hourPO.get("windDirection"))) {
                hourPO.put("windDirection", null == cityLiveWeatherMap.get("windDirect") ? "-" : WeatherUtil.changeAngleToWindDirectionByCn(String.valueOf(cityLiveWeatherMap.get("windDirect"))));
            }
            if (StringUtils.isEmpty(hourPO.get("windSpeed"))) {
                hourPO.put("windSpeed", null == cityLiveWeatherMap.get("windSpeed") ? "-" : WeatherUtil.changeWindSpeedToPowerNoCN(String.valueOf(cityLiveWeatherMap.get("windSpeed"))));
            }
        }

    }
}
